advanced
Async messaging
Use queues and streams to decouple availability and throughput, while designing for duplicates, ordering, poison messages, and replay.
Queues and event streams decouple producers from consumer availability and smooth throughput spikes. They enable temporal decoupling but shift complexity to ordering, duplicates, poison messages, replay, and schema evolution.
Use async when the caller does not need an immediate result and when buffering is acceptable. Keep critical user paths synchronous or clearly degraded.
On interviews: choose sync versus async for "order placed" notifying inventory, email, and analytics; discuss at-least-once handling.
Common pitfalls: async for operations the user waits on without UX for delay; no dead-letter queue; assuming exactly-once without design.
The trade-off is flexibility versus complexity—know when the simpler path is enough.
Checklist:
- Define delivery semantics and duplicate handling.
- Monitor lag, DLQ depth, and consumer health.
- Version event schemas with compatibility rules.
- Document replay procedures and idempotent handlers.