Scrivio Interview library
DesignIntermediate7 min read · updated 13 November 2026

An order lifecycle is the textbook event-driven domain: many services react to the same orders, and each cares about different events.

Design the topics and event contract for an e-commerce order lifecycle at about 3,000 orders a minute at peak, with roughly six events per order, consumed by fulfilment, billing, notifications, fraud, search and analytics. Cover topic names, keys, partitions, payload style, the event envelope, retention and how a new consumer gets the current state of every open order.

At 3,000 orders a minute and six events per order, the peak is only about 300 events per second, so one event topic for the order aggregate, such as sales.orders.events.v1, with 12 partitions keyed by order id, is enough and keeps every order's events in sequence. Each event carries an envelope (eventId, eventType, schemaVersion, occurredAt, orderId, a per-order sequence, correlation and causation ids, producer) and a payload with the change plus a snapshot of the fields most consumers need. The event topic keeps 7 to 14 days, a compacted sales.orders.state topic holds the latest snapshot per open order for bootstrapping, and events are published through a transactional outbox with registry compatibility checks.

Why this question is asked

The order lifecycle is the example everyone reaches for in event-driven design, so interviewers use it to see whether we can make the many small decisions concretely: names, keys, partition counts, what goes in the envelope and the payload, retention, and how a newcomer catches up. A good answer starts from the numbers, because they decide how much complexity is justified. In this answer, we will size the load, choose the topic and key, design the envelope and payload, set retention and add a state topic for bootstrapping, and finish with how events are published reliably and how schemas evolve.

1Sizing the Load First

3,000 orders a minute is 50 orders a second. With about six events per order, OrderPlaced, PaymentAuthorized, OrderConfirmed, OrderPacked, OrderShipped and OrderDelivered for example, that is about 300 events a second at peak. If an event is around 2 KB, that is 600 KB/s, tiny for Kafka, where a single partition comfortably handles several MB/s.

So throughput does not decide the partition count; consumer parallelism and growth do. Twelve partitions let up to twelve instances of each consumer group work in parallel, which is plenty for six consumers at this volume, and leaves room for ten times the traffic. Hundreds of partitions would cost broker memory, open files and slower recovery for nothing.

2One Topic for the Order Aggregate

An aggregate is a cluster of data that changes together under one owner, here an order with its lines and status. Fulfilment and billing need the events of one order in sequence: they must not see OrderShipped before OrderPlaced. Kafka orders records only within one partition of one topic, so all order events go to one topic keyed by order id, which puts every event of an order on one partition.

We name topics by domain, entity and major version, for example sales.orders.events.v1, so names say who owns them and a breaking change gets a new topic. The topic has one owning team, the order service team, who decide its schema and support its consumers. Consumers that care about only some events, such as notifications, filter by eventType, which is cheap at 300 events a second.

Topic layout for the order lifecycle
TopicKeyPartitionsCleanup and retention
sales.orders.events.v1orderId12delete, 7 to 14 days
sales.orders.state.v1orderId12compact; tombstone after archive
The event topic tells what happened; the state topic tells where every open order stands now.

3The Event Envelope and the Payload

The envelope is the set of fields every event carries regardless of type. eventId, a UUID, lets consumers detect duplicates. eventType and schemaVersion tell them how to read it. occurredAt records when the change happened in the order service. orderId repeats the key. An aggregate version, a sequence number per order that increases by one with each event, lets consumers detect gaps and stale events. correlationId ties together everything caused by one customer request, causationId points to the event or command that caused this one, and producer names the service that wrote it. Fields that consumers use for routing or filtering, such as eventType, also go into Kafka headers, so a consumer can skip a record without deserializing it.

The payload holds the facts of the change plus a snapshot of the fields most consumers need, such as the status, totals, currency and customer id. With that snapshot, billing and search rarely need to call the order service back. We leave out personal data that only one consumer needs, such as the delivery phone number, which can stay behind an API that checks access.

JSON
{
"eventId": "5b0e7c1e-...",
"eventType": "OrderShipped",
"schemaVersion": 3,
"occurredAt": "2026-11-12T14:03:22Z",
"orderId": "O-1001",
"orderVersion": 5, // fifth event of this order
"correlationId": "req-77ab",
"causationId": "evt-4410",
"producer": "order-service",
"data": { "status": "SHIPPED", "carrier": "DHL", "total": "59.90", "currency": "EUR", "customerId": "C-42" }
}

4Retention and Bootstrapping a New Consumer

The event topic uses cleanup.policy=delete with 7 to 14 days of retention. That covers consumer outages, weekend incidents and short replays, without storing years of history in Kafka. But it creates a question: when a new consumer, say a loyalty service, starts in six months, how does it learn the current state of every open order, including orders placed three weeks ago?

The answer is a second topic, sales.orders.state.v1, with cleanup.policy=compact and the same key. After each event, the order service also publishes the order's latest snapshot there. Compaction keeps at least the latest record per key, so the topic holds the current state of every order. When an order is archived, the service writes a tombstone, a record with the key and a null value, and compaction later removes the order entirely. A new consumer reads the state topic from the beginning to build its view, then switches to the event topic from around the time it started, using the per-order version to skip events it has already absorbed.

Step throughHow a new consumer catches up
  1. Read sales.orders.state.v1 from the beginninglatest snapshot per open order
  2. Store each order with its version
  3. Subscribe to sales.orders.events.v1from a timestamp shortly before the bootstrap began
  4. Event version <= stored version?
    Yesskip it, already absorbedNoapply it and store the new version

4 steps in order. Play them, or step through them one at a time.

5Publishing Reliably and Evolving the Schema

The order service writes orders to its database. If it saved an order and then crashed before publishing the event, or published and then failed to commit, the two would disagree. The transactional outbox avoids that: the service writes the event into an outbox table in the same database transaction as the order, and a relay, such as Debezium with its outbox router, publishes it to Kafka. The database and the events can no longer contradict each other.

Schemas are registered in a schema registry with BACKWARD or FULL compatibility, checked in CI before deploy. Adding an optional field is allowed; removing or renaming a required one is refused, and a truly breaking change goes to sales.orders.events.v2 with a migration period.

6Follow-up questions

How do consumers use the per-order version number when events arrive twice or out of order after a replay?

Each consumer stores the last version it applied for each order. When an event arrives, it compares: if the event's version is less than or equal to the stored one, the event is a duplicate or stale and is skipped; if it is exactly one more, it is applied and the stored version advances. If it is more than one ahead, an event is missing, so the consumer can park it and wait, or fetch the current state from the compacted state topic. This makes processing idempotent and makes gaps visible instead of silent.

Why not one topic per event type?

Because consumers such as fulfilment need OrderPlaced before OrderShipped for the same order, and Kafka has no ordering across topics. Separate topics would force every consumer to buffer and reorder. At 300 events a second, the cost of consumers filtering out the types they do not need is negligible.

Do we need both the snapshot in each event and the state topic?

They serve different needs. The snapshot fields in each event let running consumers act without calling back. The compacted state topic lets a new consumer, or one rebuilding after a bug, load the current state of every order without replaying history that retention has already deleted.

7Conclusion

In this answer, we sized the order lifecycle at about 300 events a second, chose one aggregate topic, sales.orders.events.v1, with 12 partitions keyed by order id, and designed an envelope with eventId, type, schema version, time, order id, a per-order version, correlation and causation ids and the producer. The payload carries the change plus a snapshot of commonly needed fields. The event topic keeps 7 to 14 days, while a compacted state topic with tombstones lets new consumers bootstrap. A transactional outbox keeps the database and events consistent, and registry compatibility checks guard schema changes.

What to say in the interviewAbout 80 seconds aloud

Open with

I would start from the numbers: 3,000 orders a minute times six events is about 300 events a second, which is small, so 12 partitions keyed by order id are enough and leave room for consumer parallelism and growth.

Then, if they want more

I would use one topic for the order aggregate, for example sales.orders.events.v1, named by domain, entity and major version, owned by the order team, so all events of one order stay in order.

Every event gets an envelope: eventId as a UUID for deduplication, eventType, schemaVersion, occurredAt, orderId, a per-order version or sequence, correlationId and causationId for tracing, and the producing service, with routing fields also in headers.

The payload carries the facts of the change plus a snapshot of fields most consumers need, like status, totals and customer id, but not personal data only one consumer needs. Retention on the event topic would be 7 to 14 days with delete cleanup.

For bootstrapping, I would add a compacted sales.orders.state topic with the latest snapshot per order and a tombstone when an order is archived, so a new consumer loads current state and then follows the event topic using the version to skip what it already has. I would publish through a transactional outbox and register schemas with BACKWARD or FULL compatibility.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Apache Kafka documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Design the topics and event contract for an e-commerce order lifecycle at about 3,000...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-design/c48dc41ace/