Overview
Curated: · Written: · Reviewed:
Integration Patterns
In one line
Choose the mechanism from the interaction, not the transport. Use synchronous request-response when the caller needs an answer before it can proceed, a queue to hand work to one consumer group, a log when many readers need retained history, a webhook for external push, and a file or batch exchange for bulk, loosely coupled data. Start with who owns the fact, whether the caller waits, and what redelivery, reorder and broker outage do to the design.
Key definitions
- At-least-once: the broker redelivers until acked, so duplicates are normal and the consumer must dedupe.
- Idempotency key: a stable ID (message ID, transaction ID) backed by a uniqueness constraint, so a retry lands on the same result.
- Dual write: updating a database and publishing an event as separate operations. A crash between them loses one side. A transactional outbox fixes this.
- Visibility timeout: the SQS window after which an unacked message reappears. It must exceed the handler's processing time.
- Competing consumers: workers sharing one queue. Throughput rises, but per-entity order is lost.
- Saga: a multi-step workflow whose compensations are business operations, not rollbacks.
Formulas and complexity
Five serial hops at 99.9% give about 99.5% end to end, which misses a 99.9% SLO.
This is the worst case with every hop at its p99 at once.
With backlog B, N consumers and per-consumer rate r, queue wait is roughly depth divided by drain rate. 120,000 messages at 500 msg/s is 240 s, which matches a 4-minute p99.
Per-record calls at 40 ms through 20 connections cannot finish a 2-hour window.
How it works
The outbox writes the business row and the publication intent in one local transaction. A relay then publishes and marks progress.
- The dedup key is written in the same transaction as the effect, so a duplicate hits a unique constraint and rolls back.
- Record the dedup marker after the effect commits. A marker committed before the effect can lose the effect on a crash.
- For an effect outside your database, write a pending intent row, pass the intent ID as the provider's idempotency key, then mark it done.
- Key by entity (account_id) so one partition or worker owns each account's sequence. A shared thread pool loses per-account order.
When to use and when not to
| Need | Use | Avoid when |
|---|---|---|
| Caller needs the result to proceed | Sync RPC with budgeted timeouts and bounded retries | Long chains, or a slow callee you cannot isolate |
| One consumer group, bursty load | Queue with competing consumers | You need replay for new readers or strict per-key order |
| Many readers, retained history | Log partitioned by entity key | You need one global order or exactly-once effects outside the broker |
| External producer pushes events | Webhook with HMAC, timestamp window and dedupe | You need history without a list-since-cursor API |
| Bulk, minutes-to-hours tolerance | File or batch with manifest and checksums | Per-record latency is a requirement |
Traps interviewers probe
- Ack before the effect commits. A crash after a card charge and before the ledger write leaves a charge with no row. Fix: ack after the durable write, and send an idempotency key to the charge API.
- Visibility timeout below processing time. The message reappears mid-handler and the effect runs twice. Fix: set the timeout above p99 with headroom and make the handler idempotent. Raising maxReceiveCount hides the problem and sends healthy messages to the DLQ.
- Timestamp ordering across unsynchronized clocks. A 900 ms skew makes last-write-wins keep the older status. Fix: a producer sequence or entity version with compare-and-set.
- Trusting a green broker. A 200 from the broker means the bytes were accepted, not that the business step completed. Fix: reconcile on business IDs.
- Trusting a registry compatibility check. BACKWARD mode only proves the new schema reads old data. A type change that old consumers cannot read still passes. Fix: upgrade consumers first or choose FULL compatibility, and treat meaning changes as breaking even when bytes parse.
Interview tips
Open with: "I'd first decide who owns the fact and whether the caller needs an answer before it proceeds, then pick the mechanism. I'm assuming at-least-once delivery, so the consumer dedupes."
Expect these follow-ups: the broker is down; the same message arrives twice; events arrive out of order; a replay is older than the dedup retention; a schema changes under live consumers; consumer lag keeps growing.
30-second outline:
- State the interaction: does the caller wait, who owns the fact, does order matter per entity.
- Name the mechanism and its cost (coupling, latency, replay).
- State delivery as at-least-once, with the dedup key stored with the effect.
- Solve the dual write with an outbox or a per-effect idempotency key.
- Name the backstop: reconciliation on business IDs.
- Name one number to watch: consumer lag, DLQ depth or backlog age.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.