Fullstack CourseLearn by building
Back to roadmap

Week 4 — Platform, craft & capstone

Judge when to use Redis, files, RabbitMQ, Docker, and WebSockets; then test, optimize, challenge, review, and finish Notes P4 as this week’s mini-project.

End-of-week mini-project · practice only

Realtime Orders Platform (Docker, Redis, RabbitMQ, WS)

A dockerized order service: queue work with RabbitMQ, cache with Redis, push live status over WebSockets, and prove it with tests.

Definition

A capstone platform slice where placing an order enqueues background work, a worker processes it, status streams to clients over WebSockets, and the whole stack runs under Docker Compose with tests, logging, and performance tuning.

In simpler words

Build a mini order system that behaves like production: you place an order, a background worker handles it, and your screen updates live — all running in containers.

Concepts covered this week

Caching with Redis
Cache hot order/product reads and hold rate-limit counters in Redis.
File uploads / blob / S3
Store generated invoice PDFs in a blob/S3 (or a disk adapter behind an interface).
Background work with RabbitMQ
Placing an order publishes a job; a worker consumes it and updates status.
Docker & Compose
One compose file runs api, worker, postgres, redis, and rabbitmq.
WebSockets / Socket.IO
A gateway pushes order-status changes to subscribed clients.
Configuration & secrets management
Zod-validated env; no secrets in git or logs.
Logging & observability
Structured logs + correlation IDs across api→queue→worker, plus a health check.
Postman + VS Code debugging
A Postman collection drives the API; VS Code breakpoints debug the worker.
Nest testing (unit + e2e)
Unit-test the order service; Supertest e2e for POST /orders.
Performance (indexes, lean queries, pagination)
Index orders(status, createdAt); paginate and select lean columns.
Lint, format, Nest pitfalls
ESLint/Prettier clean; avoid circular deps and request-scoped traps.
Challenge: JWT + RBAC hole
Audit and fix an endpoint that leaks another user’s orders.
Challenge: missing index / slow list
Diagnose a slow order list and add the missing index.
Challenge: broken pagination / soft-delete leak
Fix a feed whose totals include soft-deleted or duplicated rows.
Code review & feedback
Run a self code-review pass against the course rubric before "shipping".

Deliverables

  • docker-compose.yml running api + worker + postgres + redis + rabbitmq
  • POST /orders enqueues work; a worker processes it and updates status
  • WebSocket gateway pushing live status; Redis-cached reads
  • Unit + e2e tests, an indexed/paginated order list, and clean lint

Build guide

  1. Compose the stackWrite docker-compose.yml for api, worker, postgres, redis, and rabbitmq with healthchecks and validated env.
  2. Place + enqueuePOST /orders validates, persists a pending order, and publishes an order.created message to RabbitMQ.
  3. Process in a workerA separate worker consumes the queue, does the work, and updates the order status idempotently.
  4. Stream statusA Socket.IO gateway broadcasts status changes to clients subscribed to their order.
  5. Cache + tuneCache hot reads in Redis, add an index on orders(status, createdAt), and paginate the list with lean selects.
  6. Observe + debugThread a correlation id through api→queue→worker logs, add a health endpoint, and debug the worker with VS Code.
  7. Test itUnit-test the order service and write a Supertest e2e for POST /orders → status transition.
  8. Audit & reviewFix the three planted issues (RBAC leak, missing index, pagination/soft-delete leak) and do a self code-review pass.

Acceptance checklist

- [ ] docker compose up runs api + worker + postgres + redis + rabbitmq
- [ ] POST /orders enqueues; worker processes idempotently and updates status
- [ ] WebSocket clients receive live status updates
- [ ] Redis caches hot reads; orders list is indexed + paginated
- [ ] Correlation-id logging + health check; secrets only via validated env
- [ ] Unit + e2e tests pass; lint/format clean
- [ ] RBAC hole, missing index, and pagination/soft-delete leak all fixed

Stretch goals

  • Add a dead-letter queue and a retry policy for failed jobs.
  • Add Prometheus metrics and a simple dashboard.
  • Swap the disk blob adapter for real S3 without touching callers.

Tips

  • You need the seams (queue, cache, WS, Compose), not a giant cluster — keep each piece small.
  • Make the worker idempotent: the same message processed twice must not double-charge.