Java Messaging and events
Queues and logs, and the delivery guarantees people assume they have. Almost every question here reduces to duplicates and ordering.
4 concepts · 12 interview questions
What this topic covers
Every concept in messaging and events, and the questions each one gets asked as. Where a question links, it has a full write-up.
Delivery guarantees
At-most-once, at-least-once and exactly-once describe what a broker promises. Only the middle one is generally available, which makes duplicate handling the consumer's job.
- What do at-least-once and exactly-once actually mean?
- How do you write a consumer that tolerates duplicates?
- When would at-most-once be the right choice?
Ordering and partitioning
A log gives ordering within a partition only. The partition key therefore decides both parallelism and what stays in order.
- How does Kafka give you ordering, and where does it stop?
- What happens to ordering when you add consumers?
- How do you handle a message that keeps failing?
Writing to a database and a broker
A database commit and a message publish cannot be made atomic by ordering them carefully. Either the write happens without the event or the event fires without the write.
- How do you publish an event and commit a row atomically?
- What is the outbox pattern, and what does it cost?
- Why not use a distributed transaction across the two?
Event design
An event is a contract with unknown future consumers. Whether it carries state or only an identifier decides how much coupling and how much traffic it creates.
- Event notification or event-carried state transfer?
- How do you version an event schema?
- Should an event be a command or a fact?