Event-driven patterns
19 questions in 6 subtopics.
Transactional outbox
An order service saves an order with JPA and then callskafkaTemplate.send("order-created", ...) inside the same @Transactional method. What can go wrong, and how does the transactional outbox pattern solve it?Design an outbox relay for a high-volume service. Compare polling the outbox table with change data capture, and explain how you keep per-aggregate ordering and stop the table growing forever.Half of your teams publish events directly after database commits and the other half use various outbox implementations. Incidents show lost and phantom events. What platform approach would you take?Your company is moving from synchronous REST between services to an event-driven architecture. As the senior technical leader, how do you decide how far to go, and what organisational changes are needed?Saga
In a choreographed saga, an order sometimes stays in PENDING forever. Logs show the payment service failed after reserving funds and the event it should have emitted never arrived. How would you find and prevent stuck sagas?Design a saga for placing an order that reserves stock, charges payment and books shipping, each in a different service. Compare choreography and orchestration, and describe the compensations.Several teams are building their own saga frameworks. Would you adopt a workflow engine (for example Temporal or Camunda) as a company standard? How would you decide?CQRS
What is CQRS, and when is it worth separating the read model from the write model in a Spring service? What problems does it introduce?A product page in your CQRS system is built from a read model updated by events. After a change, users see their own edits disappear for a few seconds and file bugs. How would you handle this across the UI and services?Many teams build their own read models, search indexes and reporting copies from domain events, and the number of copies of core data keeps growing. How would you guide the organisation on when to build read models and how to keep the total cost under control?Event sourcing
What does event sourcing mean, and how do snapshots, projections and upcasting work in an event-sourced service?A regulator requires you to delete a customer's personal data, but your account service is event-sourced and events are immutable. How do you comply?A team proposes event sourcing as the default architecture for all new services in your company. How would you respond?Idempotent consumers
Write the core of an idempotent Kafka consumer in Spring that applies aPaymentReceived event to an account balance exactly once, even when the same event is delivered twice.Compare ways to make consumers idempotent: deduplication tables, natural idempotency (upserts, set-based updates), and version checks. Give an example where each fits.How would you make idempotent consumers a reliable practice across 40 teams rather than something each team remembers or forgets?Event schema evolution
What do backward and forward compatibility mean for events, and which changes to a JSON event are usually safe?You need to change a publishedOrderPlaced event: split "customerName" into "firstName" and "lastName" and change "amount" from a number to an object with value and currency. Eight services consume the event. How do you roll this out?Event contracts in your company have become as important as public APIs, but they change without notice and break consumers. What governance model would you put in place?No question matches these choices.