1. Order events need to reach email, fraud scoring and analytics. Would you use a queue or a log, and why?
Seniorqueueskafkapub-sub
What the interviewer is really testing
Whether you choose a broker by the semantics the use case needs (number of consumers, replay, ordering, per-message handling) and not by brand, and whether you can say what the choice costs.
Show the model answer, follow-ups and checklist
Model answer
I would start from what each consumer needs, because that decides the model.
“Order placed” is a fact that three independent systems care about, and more will follow. That is publish/subscribe: each consumer gets every event, and none of them knows about the others. The producer publishes once, and the question is what sits behind the topic.
I would use a log such as Kafka, keyed by order ID, for three reasons:
- Independent consumers. Each service is its own consumer group with its own offset. Analytics being down for an hour does not affect email.
- Replay. Fraud models are retrained and analytics pipelines are rebuilt. With a week or more of retention, a new or repaired consumer can read history. A queue would have deleted it.
- Ordering per order. Placed, paid and shipped for one order stay in sequence on one partition.
The cost is that a log gives me less control per message. One bad record blocks its partition, so each consumer needs its own retry and dead-letter handling. Consumer parallelism is capped by the partition count. Delivery is at least once, so every consumer must be idempotent on the event ID.
The email consumer is the one that fits a log least well. Sending is a task, with slow and flaky calls to a provider, and it wants per-message retries with delays. I would have a small consumer read the log and put send jobs on a queue such as SQS with a dead-letter queue, so that one stuck email does not hold up the others.
If the team is small, the volume is modest and nobody needs replay, SNS fanning out to one SQS queue per consumer is a sound alternative with far less to operate. I would say so, and choose it if those conditions hold.
Likely follow-ups
- A fourth team wants these events next quarter, including the last 30 days of history. What changes?
- With a log, nothing changes for the producer. The team creates a new consumer group and starts from the earliest offset, provided retention is at least 30 days, so I would set retention with that kind of request in mind. With SNS and SQS the new queue receives only events published after it subscribes, so the history would need a backfill from the orders database.
- Why not have the order service call the three services directly?
- Checkout would be as slow and as unreliable as the worst of the three, and every new consumer would mean a code change and a deploy for the order service. A broker lets checkout finish after one durable write and lets each consumer fail and recover independently.
- How do you make sure the event is published if the order service crashes just after committing the order?
- Use a transactional outbox. The event is inserted into an outbox table in the same database transaction as the order, and a relay publishes it to the log afterwards. The relay can publish twice, which the idempotent consumers already handle.
- Fraud scoring must be able to block a risky order. Does it still consume from the log?
- Not for the blocking decision. If checkout needs the score before it answers, that is a synchronous call with a timeout and a fallback. The log still feeds fraud's asynchronous work, such as model features and review after the fact.
Common mistakes
- Naming Kafka immediately without saying which properties of a log the use case needs.
- Putting all three services on one shared queue, so each event reaches only one of them.
- Forgetting that consumers will see duplicates and need to be idempotent.
- Treating the email sender like a stream consumer and ignoring per-message retries and dead-lettering.
- Not mentioning the simpler managed option when the scale does not justify running Kafka.
A strong answer includes
- Identifies the pattern as one event going to several independent consumers
- Chooses by semantics, naming replay, independent offsets and per-key ordering
- States the partition key and why
- States the costs: head-of-line blocking, parallelism capped by partitions, at-least-once delivery
- Separates task-style work (sending email) and gives it a queue with a dead-letter queue
- Offers SNS plus SQS as the lower-operations alternative and says when it is enough
Revise: Queues vs logs