Interview Q&A
Concept questions test whether you know the mechanism; design questions test whether you can turn requirements into keys, failure handling and monitoring. This page drills both: crisp answers grouped by theme, with links back to the pages that teach each topic, then a repeatable method and six worked prompts: order processing, notifications, clickstream, exactly-once payments, retries and search sync.
How Messaging Questions Are Asked
Messaging interviews come in two shapes. Knowledge questions ("what does acks=all do?") check that you know the mechanism. Design questions ("design a notification service") check that you can turn requirements into broker choices, keys, failure handling and monitoring. The first half of this page drills the first shape in six themes; the second half gives you a repeatable method and six worked design prompts.
Fundamentals
Delivery guarantees, ordering, idempotency, backpressure. Page 01.
Kafka
Log, partitions, replication, producers, consumers, transactions. Pages 02 to 04.
RabbitMQ
Exchanges, acks, prefetch, quorum queues, dead-lettering. Page 05.
AWS
SQS, SNS, FIFO, visibility timeout, DLQ redrive, choosing a service. Page 06.
Patterns
Outbox, inbox, saga, CQRS, event sourcing. Page 07.
Operations
Lag, alerts, DLQs, restarts, incidents. Page 08.
- Lead with the one-sentence answer, then the mechanism, then the trade-off. "Kafka keeps order only inside a partition, so messages that must stay in order share a key. The cost is that one hot key limits parallelism."
- Name the failure. Strong candidates talk about what goes wrong: duplicates, poison messages, rebalances, full disks. Weak ones describe only the happy path.
- Say "it depends" and then say on what. "Kafka or SQS?" depends on replay, fan-out, volume, ordering needs and who runs it. Name those axes.
- Never claim exactly-once end to end. The accurate sentence is "at-least-once delivery plus idempotent processing gives an exactly-once effect" (page 01).
- Tie every answer to a number you would watch. That signals operational experience (page 08).
| Theme | Pages to revise | Typical follow-up |
|---|---|---|
| Fundamentals | 01 Messaging Fundamentals | "So how would you get exactly-once?" |
| Kafka | 02 Kafka Architecture, 03 Kafka Producers & Consumers, 04 Kafka with Spring | "What happens when a broker dies mid-write?" |
| RabbitMQ | 05 RabbitMQ | "When would you pick it over Kafka?" |
| AWS | 06 AWS Messaging | "What if processing takes longer than the visibility timeout?" |
| Patterns | 07 Event-Driven Patterns | "How do you keep the database and the broker consistent?" |
| Operations | 08 Reliability & Operations | "Lag is growing: what do you do?" |
Delivery, Ordering and Idempotency
Concept questions that apply to every broker. Background: 01 Messaging Fundamentals.
- Q: Why use a message broker instead of calling a service directly?
To decouple the sender and receiver in time and availability. The producer does not wait for the consumer, a slow or down consumer does not fail the producer, bursts are absorbed by the buffer, and one message can reach many consumers. The costs are eventual consistency, more moving parts, and the need to handle duplicates and failures explicitly. - Q: Explain at-most-once, at-least-once and exactly-once delivery.
At-most-once acknowledges before processing: a message can be lost, never duplicated. At-least-once acknowledges after processing and retries until acknowledged: never lost, possibly duplicated, and the default for almost everything. Exactly-once over an unreliable network is not achievable end to end; it is at-least-once delivery combined with idempotent processing, so the effect happens once. - Q: How do you make a consumer idempotent?
Prefer natural idempotency (set absolute state, upsert by business key, version checks). Otherwise record processed message ids in a table with a unique constraint, inserted in the same transaction as the business change, and skip on a conflict. Keep dedup rows at least as long as a message can be redelivered. - Q: A command, an event and a document: what is the difference?
A command asks one receiver to do something and can be refused ("charge this card"). An event states a fact that already happened and has any number of listeners ("order placed"). A document carries data for a receiver to use. Events and commands need different contracts, naming and ownership. - Q: How is ordering preserved, and what does it cost?
Ordering is only guaranteed within a single ordered lane (a Kafka partition, an SQS FIFO message group, one RabbitMQ queue with one consumer). Messages that must stay in order share a key that routes them to the same lane. The cost is parallelism: one lane is processed by one consumer at a time. - Q: What is backpressure?
The mechanism by which a slow consumer limits the rate of its producer so the system does not overflow. In practice you choose in advance between buffering (let the queue grow and scale out), slowing the producer (bounded buffers, rate limits) and shedding load (drop stale or low-value work). - Q: What is a poison message and a dead-letter queue?
A poison message is one that always fails, so retrying forever blocks the lane or burns resources. After a bounded number of retries it is moved to a dead-letter queue with failure metadata so the lane keeps flowing, and a person or a job inspects it. A DLQ without an alert and an owner is a silent data-loss mechanism. - Q: Why do duplicates happen even in a reliable system?
Because "reliable" means "never lost", and the only way to guarantee that over a network is to resend when unsure. A consumer that crashes after processing but before acking, a producer that retries after a lost acknowledgment, or a timeout that hands the message to a second consumer all create duplicates.
Log, Replication and Clients
Background: 02 Kafka Architecture, 03 Kafka Producers & Consumers, 04 Kafka with Spring. Facts below match Apache Kafka 4.0.
- Q: How is Kafka different from a traditional message queue?
Kafka is a partitioned, replicated, append-only log. Messages are retained for a configured time or size regardless of whether they were read, each consumer group tracks its own offset, and any group can replay. A queue deletes a message once acknowledged and tracks delivery per message. - Q: What is a partition and what does it determine?
One ordered log of a topic. It is the unit of ordering (order holds only within it), of parallelism (one consumer per partition within a group), of replication and of deletion (retention removes whole segments). A record is addressed by topic, partition and offset. - Q: Explain leader, follower, ISR and high watermark.
Each partition has one leader that handles all reads and writes; followers copy from it. The in-sync replicas are the leader plus followers that are caught up withinreplica.lag.time.max.ms(30 s by default). The high watermark is the highest offset replicated to all ISR members, and consumers read only below it. - Q: How do you configure Kafka so acknowledged data is never lost?
Replication factor 3,min.insync.replicas=2, produceracks=allwith idempotence on,unclean.leader.election.enable=false, and replicas spread across racks or zones. That survives one broker failure without loss and refuses writes instead of risking loss when two are down. - Q: What does the idempotent producer fix, and what does it not?
It stops retries by the same producer session from creating duplicates in a partition, using a producer id and per-partition sequence numbers. It is on by default in Kafka 3.0 and later (withacks=all, retries above 0 and at most 5 in-flight requests). It does not stop your application from sending the same business event twice, and it does not span restarts of the process. - Q: What are Kafka transactions and what do they guarantee?
A producer with atransactional.idcan write to several partitions and commit the consumer offsets atomically (sendOffsetsToTransaction), so a read-process-write cycle inside Kafka either all happens or none of it. Consumers see only committed data whenisolation.level=read_committed(the default isread_uncommitted). This is exactly-once within Kafka; effects in a database or an HTTP call are outside it. - Q: How do consumer groups and rebalancing work?
The partitions of a subscribed topic are divided among the members of a group, one owner per partition. When members join, leave or are considered dead (no poll withinmax.poll.interval.ms, default 5 minutes, or no heartbeat withinsession.timeout.ms, default 45 s) the group rebalances. With the classic protocol that pauses affected consumers, which is why cooperative assignment, static membership and the KIP-848 protocol in 4.0 matter. - Q: When do you commit offsets, and what goes wrong at each choice?
Committing after processing gives at-least-once: a crash between processing and commit repeats messages. Committing before processing gives at-most-once: a crash loses them. Auto-commit (enable.auto.commitdefaults to true) commits on a timer, which can commit messages you have polled but not finished. Prefer manual commits after the work is done. - Q: What happens if you add partitions to a keyed topic?
The mapping from key to partition depends on the partition count, so existing keys can start landing on different partitions, breaking per-key order and any state keyed by partition. Partitions can be added but never removed, so choose the count with headroom up front. - Q: Delete versus compact cleanup policy?
deleteremoves old segments by age or size (7 days by default).compactkeeps at least the latest record per key and removes older ones in the background; a null value is a tombstone that deletes the key afterdelete.retention.ms. Compaction suits "latest state per key" topics, not event history. - Q: What changed with KRaft?
Cluster metadata moved from ZooKeeper into an internal Raft-replicated log (__cluster_metadata) managed by controller nodes. ZooKeeper support was removed in Kafka 4.0, so KRaft is the only mode, and one fewer system has to be operated.
Exchanges, Acks and Quorum Queues
Background: 05 RabbitMQ. Facts match RabbitMQ 4.x.
- Q: Describe RabbitMQ's routing model.
Producers publish to an exchange, never directly to a queue. The exchange routes each message to bound queues by rules:direct(exact routing key),topic(pattern with*and#),fanout(every bound queue) andheaders(header matching). Consumers read from queues. The default exchange routes by queue name. - Q: How do acknowledgments work, and what are publisher confirms?
A consumer acknowledges a delivery after processing; an unacknowledged message is redelivered if the channel closes. In the other direction, publisher confirms let the broker tell the producer that it has taken responsibility for a message. Without confirms a publish can be lost silently; with consumer acks and publisher confirms you get at-least-once end to end. - Q: What is prefetch and why does it matter?
It limits how many unacknowledged messages the broker sends a consumer. Too high and one consumer hoards messages while others idle, and a crash redelivers a large batch; too low and the consumer waits on the network. The count of unacknowledged messages is a key metric. - Q: What are quorum queues and how do they differ from classic queues?
Quorum queues are replicated, durable queues based on the Raft consensus protocol: a message is confirmed once a majority of replicas have it, and a queue stays available while a majority is online. They are the recommended type for data safety. Classic mirrored queues were removed in RabbitMQ 4.0. - Q: How does RabbitMQ handle poison messages?
Failed messages can be rejected without requeue and routed by a dead-letter exchange. Quorum queues also count failed deliveries (x-delivery-count) and, from RabbitMQ 4.0, dead-letter or drop after a delivery limit that defaults to 20, configurable with thedelivery-limitpolicy. - Q: What happens when RabbitMQ runs out of memory or disk?
A resource alarm blocks connections that publish (the node stops reading from them) while consumers keep working, so a backlog can turn into a publisher outage. The memory alarm triggers at thevm_memory_high_watermark(default 0.6 of RAM) and the disk alarm atdisk_free_limit. - Q: When would you choose RabbitMQ over Kafka?
When you need flexible routing, per-message acknowledgment, priorities or TTLs, request-reply, and task-queue semantics at moderate volume, and you do not need long retention or replay. Choose Kafka when the event stream and replay are the product, volumes are high, or many independent consumers read the same data.
SQS, SNS and Choosing a Service
Background: 06 AWS Messaging. Numbers below were checked against the Amazon SQS developer guide.
- Q: Standard versus FIFO SQS queues?
Standard queues have nearly unlimited throughput, at-least-once delivery and best-effort ordering, so duplicates and reordering happen. FIFO queues keep order within aMessageGroupIdand deduplicate sends (deduplication id) within a 5-minute window, at lower throughput limits (see the quotas page). Use FIFO only when order or send-side dedup is required. - Q: What is the visibility timeout?
When a consumer receives a message it becomes invisible to others for the visibility timeout (default 30 seconds, maximum 12 hours). If the consumer deletes it in time, done; if not, the message becomes visible again and is redelivered. Set it above your worst-case processing time, or extend it withChangeMessageVisibility. - Q: How does the SQS dead-letter queue work?
A redrive policy on the source queue names a DLQ and amaxReceiveCount: after that many receives without a delete, SQS moves the message to the DLQ. The DLQ must be in the same account and Region and must be the same queue type. Give the DLQ a longer retention period than the source queue, because for standard queues expiry is based on the original enqueue time. - Q: How do you redrive a DLQ?
Fix the cause first, then use the message move task (console "Start DLQ redrive", orStartMessageMoveTask) to move messages back to the source queue or another queue of the same type, with a maximum rate (up to 500 per second) that you ramp gradually. You cannot filter or modify messages during the move (page 08). - Q: How do SNS and SQS work together?
SNS is publish/subscribe: a topic fans a message out to subscribers. Subscribing an SQS queue per consumer gives each consumer its own durable buffer, retries and DLQ, so a slow consumer does not affect the others. The queue policy must allow the topic to send. SNS also supports cross-Region delivery to SQS queues. - Q: Kafka (or MSK) versus SQS versus Kinesis?
SQS: simple, fully managed task queue, no ordering unless FIFO, no replay. Kafka or MSK: log with long retention, replay, many consumer groups and high throughput, more to design and operate. Kinesis: AWS-native streaming with shards, similar in spirit to Kafka. Pick by replay need, fan-out, ordering, volume and operational appetite. - Q: What is the maximum SQS message size, and what do you do with larger payloads?
The maximum is 1 MiB (1,048,576 bytes). For larger data store the payload in S3 and send a reference, or use the SQS Extended Client Library. - Q: What is long polling and why use it?
AReceiveMessagecall that waits for up to 20 seconds for a message to arrive instead of returning immediately. It reduces empty responses, API cost and latency. Short polling is the default if you do not set a wait time.
Outbox, Saga and Friends
Background: 07 Event-Driven Patterns.
- Q: What is the dual-write problem and how does the outbox solve it?
Saving to a database and sending to a broker are two systems with no shared transaction, so a crash between them leaves an order without an event or an event without an order. The transactional outbox writes the business row and an event row to an outbox table in one local transaction, and a separate relay publishes the outbox rows, retrying until they are sent. It turns a lost event into a possible duplicate. - Q: Polling relay versus change data capture for the outbox?
A polling publisher queries the outbox table periodically: simple, but adds database load and latency and needs care with ordering. Log-based CDC (for example Debezium) reads the database transaction log and streams outbox rows with low latency and no polling load, at the price of running another component. - Q: What is the inbox pattern?
The receiving side of the same idea: record each processed message id in a table inside the same transaction as the business change, so a redelivered message is detected by the unique constraint and ignored. It makes at-least-once delivery harmless. - Q: Choreography or orchestration for a saga?
In choreography each service reacts to events and emits its own, with no central coordinator: loosely coupled but the overall flow is hard to see. In orchestration a coordinator tells each participant what to do next and handles compensation: easier to follow and monitor, but it is a central component. Prefer orchestration as flows grow beyond a few steps. - Q: What is a compensating action?
A saga cannot roll back across services, so each step that has an effect has a second step that semantically undoes it (refund a payment, release stock). Compensations must themselves be idempotent and retryable, and some effects (an email sent) cannot be undone and need a different treatment. - Q: What is CQRS and when is it worth it?
Command Query Responsibility Segregation separates the write model from one or more read models, usually fed by events. It pays off when reads and writes have very different shapes or scale. It costs eventual consistency between the two sides and more infrastructure, so it is not a default. - Q: What does event sourcing cost?
You store the sequence of events as the source of truth and derive state by replaying them, which gives a full audit trail and time travel. The costs are schema evolution of old events forever, rebuilding projections, snapshots for long streams, and a steep learning curve for the team.
Lag, Alerts and Incidents
Background: 08 Reliability & Operations.
- Q: Consumer lag is growing. What do you do?
Work through three checks in order. Is the consumer running and polling (crashed, stuck, or being rebalanced)? Is it slow (processing time, a dependency, a recent deploy; produce rate versus consume rate)? Is the lag skewed to one partition (hot key or poison message)? Fix the cause; add consumers only up to the partition count and only if the dependency can take the load. - Q: What do you alert on for a queue, and why?
The age of the oldest message (on SQSApproximateAgeOfOldestMessage, on Kafka lag in time), because it is the delay users feel and is independent of volume. Queue depth alone fires on harmless bursts. Add DLQ depth above zero, under-min-ISR and offline partitions for Kafka, and resource alarms for RabbitMQ. - Q: How do you restart a Kafka cluster with no downtime?
One broker at a time with controlled shutdown so leaders move first, then wait until under-replicated partitions return to 0 before touching the next. Replication factor 3 andmin.insync.replicas=2are what make a single broker outage safe. - Q: How do you redrive a DLQ safely?
Inspect to find the cause, fix and deploy, test with a few messages, redrive at a limited rate while watching the consumer error rate and queue age, and make sure consumers are idempotent because some of these messages may have had partial effects. - Q: Producers report NotEnoughReplicas. What is wrong?
The in-sync replica set of some partitions is belowmin.insync.replicas, soacks=allwrites are rejected. Checkkafka-topics.sh --describe --under-min-isr-partitions, find which broker is down or out of sync (disk, network, overload) and restore it. Do not lowermin.insync.replicasto silence the error. - Q: What is a rebalance storm?
Consumers that exceedmax.poll.interval.msor miss heartbeats are evicted, which triggers a rebalance that pauses everyone, grows the backlog and makes the next batch slower, so more consumers are evicted. Reduce batch size, fix pauses, use static membership and cooperative assignment, and avoid a flapping autoscaler.
Answering a Design Question
Design prompts are open on purpose. The interviewer wants to see your process, so give them one. Use the same six steps every time; it keeps you from jumping to "use Kafka" before knowing what the problem is.
| If the requirement is... | Lean towards | Why |
|---|---|---|
| Replay history, many independent consumers, high volume, stream processing | Kafka (or MSK) | Retained log, per-group offsets, partition parallelism |
| Task queue with retries, delays and a DLQ, little to operate, on AWS | SQS (standard; FIFO if order or send dedup) | Fully managed, per-message visibility and redrive |
| Fan-out to several services, each with its own buffer | SNS to SQS (or Kafka consumer groups) | Each consumer isolated with its own retries and DLQ |
| Complex routing, per-message TTL or priority, request-reply, moderate volume | RabbitMQ | Exchanges, bindings, rich per-message control |
| Route events by content to targets and SaaS integrations on AWS | EventBridge | Rule-based event bus rather than a high-throughput log |
| Strict order for one entity at modest throughput | Kafka partition key, SQS FIFO group, or one RabbitMQ queue and consumer | A single ordered lane per key |
State the choice and what would change it: "SQS because it is a task queue on AWS and nobody wants to run a cluster; if we later need to replay the last 30 days, that pushes us to Kafka."
- "We would use Kafka" is not a design. A design says what is in the message, what the key is, where it can be lost or duplicated, how that is made safe, and what you would look at on the dashboard when it breaks. Spend at most a minute on the broker name and the rest on those questions.
Six Scenarios with Outlines of Strong Answers
Each prompt below shows the outline of an answer an interviewer would be happy with, in the order of the method from chapter 8. Treat the numbers as examples of the kind of reasoning, not as facts about any real system.
Prompt: An e-commerce site takes orders. After checkout, payment, inventory, shipping and notification must happen, reliably, and each team deploys independently.
| Step | What a strong answer says |
|---|---|
| Requirements | No lost orders; payment must not be taken twice; shipping can lag by minutes; peak traffic on sale days; a failure in notifications must not block payment. |
| Broker choice | Kafka: several independent consumers read the same order events, history is useful for audit and replay, and volume spikes. SQS with SNS fan-out is a fair alternative if replay is not needed and the team wants no cluster. |
| Keys and ordering | Key by orderId so events of one order are in order; different orders in parallel. Partition count from peak throughput and consumer time (page 02), with headroom because it cannot shrink. |
| Failure handling | Checkout writes order plus an outbox row in one transaction; a relay publishes. Each consumer retries transient errors with backoff and dead-letters permanent ones. A saga (orchestrated) coordinates payment, stock and shipping, with compensation (refund, release stock) when a step fails. |
| Idempotency | Every consumer has an inbox keyed by event id; payment also uses an idempotency key towards the card network. Natural idempotency where possible (set status, not increment). |
| Monitoring | Time-lag per consumer group, saga stuck-in-state age, DLQ depth per service, under-min-ISR partitions, and a business metric (orders placed minus orders shipped within SLA). Runbook for each alert (page 08). |
- "What if payment succeeds but the stock reservation fails?" (compensation: refund, and the refund is itself idempotent and retried.)
- "How do you replay yesterday's orders into a new analytics service?" (new consumer group from an earlier offset: the benefit of the log.)
- "How do you deploy a new event version?" (additive schema changes, tolerant readers, versioned event types, page 07.)
Prompt: Many services send user notifications. Users have preferences, providers rate-limit, and a provider outage must not lose or spam anyone.
| Step | What a strong answer says |
|---|---|
| Requirements | Accept requests from many services; honour preferences and quiet hours; provider rate limits; at-least-once with no visible duplicates; priority for security codes over newsletters. |
| Broker choice | A task-queue shape: SQS (or RabbitMQ) per channel and priority, because per-message retry, delay and DLQ matter and replay does not. Kafka is also reasonable for the intake topic if a stream of requests is wanted for analytics. |
| Keys and ordering | Mostly no ordering. Where "send A then B to this user" matters, group by user id (FIFO message group, or a Kafka key). Separate queues for urgent (login codes) and bulk (marketing) so one cannot starve the other. |
| Failure handling | Bounded retries with exponential backoff and jitter; a provider outage opens a circuit and messages wait in the queue rather than being dropped; a maximum useful age (a login code expires, so drop it after a few minutes, do not send it late). Poison requests (invalid address) go straight to the DLQ. |
| Idempotency | A notification id from the caller, stored in a dedup table before sending; pass it to the provider if it supports idempotency keys. "Mark sent" and "call provider" are not atomic, so accept a rare duplicate and prefer it over a loss for non-critical messages. |
| Monitoring | Message age per queue (the SLO is time to send), provider error rate and latency, DLQ depth, rate-limit rejections, send rate versus provider quota. |
- "How do you stop a retry storm when the provider comes back?" (jitter, rate-limited consumers, ramp up.)
- "How do you honour unsubscribe immediately?" (check preferences at send time, not at enqueue time.)
- "How do you prioritise?" (separate queues or topics; Kafka has no per-message priority.)
Prompt: A website produces user events at high volume. Analytics wants them in near real time and in a data lake, and the website must never slow down.
| Step | What a strong answer says |
|---|---|
| Requirements | Very high write volume; small loss is acceptable for some events but not for billing-relevant ones; many consumers (dashboards, lake, fraud); replay when logic changes; the website must not block on the pipeline. |
| Broker choice | Kafka (or MSK or Kinesis): high throughput, retention, replay and many consumer groups are exactly what a log is for. A queue would delete data after the first consumer. |
| Keys and ordering | Key by userId or sessionId when per-user order matters for sessionisation, but watch for skew: a few extremely active keys create a hot partition. If order does not matter, no key, for even spread. Size partitions from throughput (page 02), compress batches, and batch with linger.ms. |
| Failure handling | Producers send asynchronously with bounded buffers; when the buffer fills, drop or sample low-value events rather than block the page (explicit load shedding). Billing-relevant events use acks=all and an outbox. Consumers commit after a successful write to the sink; the lake sink is idempotent (partition files by offset range). |
| Idempotency | At-least-once into the lake with deterministic file names, or dedupe on event id downstream. Dashboards usually tolerate small duplicates. |
| Monitoring | Produce error rate, consumer time-lag per sink, partition skew (bytes per partition), disk and retention headroom, request handler idle on brokers. |
- "What if one user generates 30% of the events?" (hot partition: a more granular key, or salting, depending on whether order is needed.)
- "How long do you keep the data?" (retention covers the longest replay or outage you need to survive; the lake is the long-term store.)
- "How do you handle schema changes?" (schema registry or versioned envelope, compatible changes only.)
Prompt: A payment must debit an account exactly once, even with retries, crashes and duplicate messages. The interviewer will ask whether "exactly-once" exists.
| Step | What a strong answer says |
|---|---|
| Requirements | Money moves once; every payment is traceable; the client may retry; downstream ledger and notification must reflect it once. |
| Say the honest thing first | Exactly-once delivery does not exist over an unreliable network. We build an exactly-once effect from at-least-once delivery plus idempotent processing at every hop. |
| Broker choice | Any durable broker works because correctness lives in the idempotency design. A Kafka topic is typical for the payment event stream; Kafka transactions give atomic consume-process-produce inside Kafka, but the database debit and the card network are outside it. |
| Keys and ordering | Key by account id so events for one account are ordered; payment id is the idempotency key. |
| Idempotency and failure handling | Client sends an Idempotency-Key; the service inserts it with a unique constraint in the same transaction as the payment row and an outbox row, and returns the stored result for a repeat. The relay publishes with the idempotent producer; the ledger consumer uses an inbox table. The card network call carries the same key. Unknown outcomes (a timeout) are resolved by querying the status, never by blind retry. |
| Monitoring | Payments stuck in a pending state beyond a threshold, reconciliation between the payment table and the ledger (the safety net), DLQ depth, duplicate-key hit rate (a rising number means clients or relays are retrying a lot). |
- "Does Kafka give exactly-once?" (Within Kafka read-process-write with transactions and
read_committed; not for external side effects.) - "What if the DB commit succeeds and the publish fails?" (that is why the outbox exists: the event row is committed with the payment.)
- "How long do you keep idempotency keys?" (at least as long as a retry or redelivery could occur.)
Prompt: A consumer calls a flaky downstream API. Design retries so that transient failures recover, permanent failures do not loop forever, and the main flow keeps moving.
| Step | What a strong answer says |
|---|---|
| Requirements | Recover from transient errors; do not hammer a struggling service; bound total effort; never block unrelated messages; keep failed messages for inspection. |
| Classify errors | Transient (timeout, 503, deadlock): retry. Permanent (malformed payload, validation, a 4xx): dead-letter immediately, since retrying cannot help. |
| Mechanism | Short in-process retries for a few quick attempts. Longer delays go through retry topics or queues with increasing delay (for example 5 s, 1 min, 15 min), so the main lane keeps flowing. SQS gives delay with the visibility timeout and delay queues; RabbitMQ with TTL plus dead-lettering back; Kafka with retry topics (Spring Kafka provides non-blocking retry topics, page 04). |
| Backoff | Exponential backoff with jitter so many consumers do not retry in lockstep (page 01 builds the formula). Cap the attempts and the total age. |
| Idempotency | A retry means the first attempt may have partly succeeded, so the handler must be idempotent, and the downstream call carries an idempotency key if supported. |
| Monitoring and protection | Retry rate per stage, DLQ depth, age of oldest message. Add a circuit breaker so that while the downstream is down you stop calling it and let messages wait, rather than burning attempts. |
- "Why not just retry in a loop in the handler?" (it blocks the partition or holds the message, and a long outage exhausts the budget; use it only for short in-process retries.)
- "What about message ordering during retries?" (a retried message can arrive after later ones; for strict order retry in place, accept the blocking, or make processing order-insensitive with version checks.)
- "How do you replay the DLQ?" (page 08 checklist: fix, test, rate-limit, idempotent.)
Prompt: Product data lives in a relational database. A search service needs an up-to-date index, and a missed update means users cannot find products.
| Step | What a strong answer says |
|---|---|
| Requirements | Eventually consistent within seconds; no missed updates; the ability to rebuild the index from scratch; the database must not be slowed down much. |
| Broker choice | Kafka with change data capture (Debezium reads the database log into topics) or an outbox table relayed to Kafka. A compacted topic keyed by product id gives the latest state per product, which also makes a full rebuild easy. |
| Keys and ordering | Key by product id so updates to one product arrive in order; the indexer then applies them in sequence. Include a version or timestamp so a late duplicate cannot overwrite newer data. |
| Failure handling | The indexer retries transient failures; poison records go to a dead-letter topic and are alerted. If the index is corrupted, reset the consumer group to the beginning of the compacted topic and rebuild (replay, the benefit of a log). |
| Idempotency | Indexing by product id is naturally idempotent: writing the same document twice gives the same index. |
| Monitoring | Time-lag of the indexer, DLQ depth, and a periodic reconciliation job comparing row counts or checksums between database and index. |
- "Why not write to the database and the index in the same request?" (dual write: one will eventually fail; use outbox or CDC.)
- "What happens on a deletion?" (a tombstone for the key; the indexer deletes the document.)
- "How do you initially load the existing data?" (a snapshot phase of CDC, or a one-time backfill into the topic, then streaming.)
Cheat Sheet and Recap
| If asked about... | Say | Then mention |
|---|---|---|
| Exactly-once | At-least-once delivery plus idempotent processing equals an exactly-once effect | Kafka transactions are exactly-once only inside Kafka |
| Ordering | Per lane only: Kafka partition, SQS FIFO group, one RabbitMQ queue | Same key means same lane; hot key limits parallelism |
| Durable Kafka write | RF 3, min.insync.replicas=2, acks=all, no unclean election | Idempotent producer on by default since 3.0 |
| Kafka vs queue | Log with retention, replay and per-group offsets vs delete-on-ack | Choose by replay, fan-out and volume |
| Consumer rebalance | Missed poll or heartbeat triggers it; classic protocol pauses everyone | Cooperative assignor, static membership, KIP-848 in 4.0 |
| RabbitMQ safety | Quorum queues, publisher confirms, consumer acks, DLX | Delivery limit defaults to 20 in 4.0; resource alarms block publishers |
| SQS basics | Visibility timeout (30 s default), maxReceiveCount, DLQ, long polling (20 s max) | FIFO: message group id and 5-minute dedup window; 1 MiB message limit |
| Dual write | Outbox in the same transaction, relay with polling or CDC | Inbox on the consumer; duplicates become harmless |
| Lag growing | Running? slow? skewed? | Alert on age, not depth |
| Safe restart / redrive | One node at a time gated by URP or quorum; redrive after fix, small first, rate-limited | Idempotency makes both safe |
- Know the mechanism, then the failure. For each broker feature, know what goes wrong without it.
- Be exact about guarantees: exactly-once is an effect built from idempotency, not a property of a broker.
- Use the six-step method for design: requirements, broker, keys, failure handling, idempotency, monitoring.
- Choose a broker by replay, fan-out, routing, volume and operations, and say what would change your mind.
- Always close with how you would watch it: age, lag, DLQ depth, replication health, plus a runbook.
- Make numbers explicit (peak rate, processing time, partitions needed); it shows engineering judgement.
Facts on this page were cross-checked on 2026-10-31 against the Apache Kafka 4.0 configuration reference (defaults for acks, idempotence, isolation.level, enable.auto.commit, max.poll.interval.ms, session.timeout.ms), the RabbitMQ 4.x documentation (quorum queue delivery limit, resource alarms), and the Amazon SQS developer guide (visibility timeout, message size, retention, long polling, DLQ and redrive). Consistency with pages 01 and 02 of this section was checked by hand. Throughput limits and prices are intentionally not quoted: see the vendor quota pages.
- 08 Reliability & Operations - the numbers and runbooks behind chapter 7.
- Kafka Architecture and Messaging Fundamentals - the two pages most questions come from.
- Messaging Map - the whole section.