Dualo
System Design Essentials

Message Queues & async processing

Decouple producers from consumers with a queue in between. Smooths traffic spikes, enables async work, and isolates failures.

1 min read

A **** (or broker) sits between two systems. The producer pushes messages; consumers pull them at their pace. If the consumer is slow, messages buffer up — the producer doesn't have to wait or fail.

When to reach for one: (a) smooth a traffic spike (10k signups/minute during a launch → buffer → process at 1k/min steadily), (b) async work (send a welcome email after signup — don't block the signup response), (c) isolate failures (email server is down → messages wait in queue, system recovers when it's back), (d) fan-out (one event → notify 5 downstream systems).

**Delivery guarantees**: **at-most-once** (send and forget — may lose messages, never duplicate), **at-least-once** (retry until acked — never lose but may duplicate; most common), **exactly-once** (very hard in distributed — usually approximated via consumers).

**Tools**: **RabbitMQ** (traditional queue, easy to use, solid for most needs), **** (high-throughput event log, retain history, multi-subscriber), **AWS SQS / Google Pub/Sub / Azure Service Bus** (managed cloud queues, zero ops), **Redis Streams** (lightweight queue-like), **NATS** (low-latency, cloud-native). Choose by scale + features needed.

Idempotency is the consumer's duty: if you might receive the same message twice (at-least-once), processing it twice must not double-charge / double-email. Solve via a dedup key + a 'seen' table, or by making operations naturally idempotent (SET balance = 100 vs ADD 10 to balance).

** (DLQ)**: a separate queue for messages the consumer failed to process after N retries. Not silently dropped — accumulated for inspection. Critical for debugging and not losing data.

Diagram

Grounded on https://kafka.apache.org/intro

Next up

API Design — REST, RPC, GraphQL

Resource-oriented REST is the default. RPC (gRPC) for internal high-throughput. GraphQL for flexible client-driven queries. Pick by fit, not fashion.