Advanced Architecture and Scaling
Event-driven workflows, distributed consistency, read models, tenant-aware capacity, and disciplined evolution
Events and Transactional Outbox
Commands request actions; events record facts. Use domain events when they decouple meaningful modules, not for every function call.
How to apply it
Write the domain change and outbox row in one transaction. A worker publishes pending events; consumers deduplicate stable IDs. Version schemas, plan replay/retention, and keep payloads minimal.
Worked example
Project creation and a ProjectCreated outbox record commit together; if the broker is unavailable, a worker publishes later.
Common mistakes to avoid
Writing to database and broker as uncoordinated operations or assuming exactly-once delivery.
Practice task
Implement this concept in the capstone. Add one positive test, one negative or failure-path test, and a short note explaining the trade-off you chose.
- Commands request actions; events record facts. Use domain events when they decouple meaningful modules, not for every function call.
- Write the domain change and outbox row in one transaction.
What is the strongest production practice for Events and Transactional Outbox?
Sagas and Distributed Consistency
A saga coordinates local transactions across systems that cannot share an atomic transaction.
How to apply it
Define durable step state, idempotency, timeout, retry, compensation, and operator recovery. Compensation is a business action: a payment may require a refund, while an email cannot be unsent. Expose pending states honestly.
Worked example
Provisioning creates a workspace, allocates resources, configures a provider, and sends an invite; failed provider setup triggers retry or documented compensation.
Common mistakes to avoid
Reporting success before critical work completes or assuming every side effect can be rolled back.
Practice task
Implement this concept in the capstone. Add one positive test, one negative or failure-path test, and a short note explaining the trade-off you chose.
- A saga coordinates local transactions across systems that cannot share an atomic transaction.
- Define durable step state, idempotency, timeout, retry, compensation, and operator recovery.
What is the strongest production practice for Sagas and Distributed Consistency?
Caching, Search, and Noisy Neighbors
Search indexes are derived read models, not authorities for permissions or billing. Cache keys must include every response-changing dimension.
How to apply it
Use TTLs, invalidation events, stampede protection, and current authorization checks. Measure tenant resource use and enforce fair quotas/concurrency. Consider CQRS or dedicated tenant infrastructure only when evidence justifies complexity.
Worked example
Cap report concurrency for a heavy tenant so smaller tenants' interactive work remains responsive.
Common mistakes to avoid
Caching permissions indefinitely or extracting services based on arbitrary tenant-count thresholds.
Practice task
Implement this concept in the capstone. Add one positive test, one negative or failure-path test, and a short note explaining the trade-off you chose.
- Search indexes are derived read models, not authorities for permissions or billing. Cache keys must include every response-changing dimension.
- Use TTLs, invalidation events, stampede protection, and current authorization checks.
What is the strongest production practice for Caching, Search, and Noisy Neighbors?