Quick revision
The short answer
I would set a small mandatory header set on every event: event id, event type and version, source, correlation and causation ids, and W3C trace context, written into the event contract and added by default by the platform's client libraries in every language. Tracing is sampled, full for critical flows and head-sampled for high-volume streams, and the event id plus correlation id fill the gaps through a lookup tool that follows one event across topics and consumers. Rollout goes by business importance, with coverage tracked per service.
What to remember
In this answer, we saw that following events needs two things: cheap metadata on every event and sampled traces where they are worth the cost. We defined a small header set based on CloudEvents with correlation, causation and trace context, made the platform's starters add it in every language, sampled by flow importance while avoiding high-cardinality attributes, built a lookup by event id for incidents, and rolled it out by business importance with visible coverage.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would set a small mandatory header set on every event: event id, event type and version, source, correlation and causation ids, and W3C trace context, written into the event contract and added by default by the platform's client libraries in every language. Tracing is sampled, full for critical flows and head-sampled for high-volume streams, and the event id plus correlation id fill the gaps through a lookup tool that follows one event across topics and consumers. Rollout goes by business importance, with coverage tracked per service.
Why this question is asked
At 300 services and five languages, consistency cannot come from asking each team to do the right thing. Incident reviews that cannot follow an event are a symptom of missing shared metadata, and tracing everything at 2 million records per second would cost more than it is worth. Interviewers ask this to see how a senior engineer balances a standard, its cost and its adoption. In this answer, we will define the header set, decide how the platform enforces it, design sampling with the numbers, build the lookup that incidents actually need, and plan the rollout.
1Why Metadata, Not Just Tracing
Two different questions come up in an incident. The first is what happened to this specific event: which consumers read it, what each one did, and where it failed. The second is how long each step of a flow took. Traces answer the second well, but only for sampled requests. The first needs every event to carry stable identifiers, whether or not it was traced.
So the standard has two parts: metadata on every event, which is cheap, and traces on a chosen share of events, which is expensive.
2The Mandatory Header Set
We keep it small, so teams accept it and it costs little at 2 million records per second. Rather than inventing names, it is sensible to adopt the CloudEvents binding for Kafka, an open standard that defines ce_-prefixed headers and has libraries in all major languages.
| Header | Example | Purpose |
|---|---|---|
| ce_id (event id) | 01JC9V2K7Q... | Unique; dedupe and lookup |
| ce_type and version | com.acme.order.placed.v2 | Routing and schema choice |
| ce_source | /services/checkout | Which service produced it |
| correlation-id | id of the user action | Ties every event from one action together |
| causation-id | id of the event that caused this one | Builds the chain step by step |
| traceparent | 00-<trace id>-<span id>-01 | Joins traces when sampled |
3Making the Platform Add Them
Compliance that depends on each of 300 teams will reach perhaps 60 percent. So the platform team ships client configurations and small starter libraries for each language: a Spring Boot starter with a producer interceptor and observation enabled, and equivalents for the other four languages built on OpenTelemetry instrumentation. They generate the event id, copy the correlation id from the incoming request or event, set the causation id to the id of the event being handled, and inject trace context, all without application code.
A contract check in CI rejects event schemas without the documented headers, and a light check in production samples records per topic and reports missing headers on a dashboard.
4Sampling That the Budget Allows
At 2 million records per second, tracing 100 percent means 2 million producer spans and several million consumer spans every second, a bill that easily exceeds the cost of Kafka itself. Head-based sampling decides at the start of a request whether its trace is kept, and the decision travels in the traceparent flags, so every service agrees. We set it by flow: 100 percent for critical, lower-volume flows such as payments, and 0.1 percent for high-volume streams such as clickstream, which still gives 2,000 traces per second of good samples.
Cost also comes from cardinality. Span attributes such as user id or order id create huge index sizes in many backends, so the standard says to keep identifiers in events and logs, and keep span attributes to bounded values such as topic and event type.
- Is the flow on the critical list?YesSample 100 percentNoUse the stream's head-sampling rate
- Is this record sampled?YesProducer and consumer spans with traceparentNoHeaders only, no spans
- Incident on an unsampled event?YesFind it by event id and correlation idNoUse the trace
3 steps in order. Play them, or step through them one at a time.
5The Lookup Tool Incidents Actually Need
Most incident questions are about one event: where did order 812 go. So the platform provides a lookup: given an event id or correlation id, it shows which topics, partitions and offsets hold matching events, and what each consumer did with them. Each consumer logs one structured line per event with the event id, outcome and duration, which the starters do automatically, and an index over event ids and correlation ids makes the search take seconds.
This answers the incident question for every event, sampled or not, at a fraction of the cost of full tracing, and it is often more useful than a trace because it covers consumers that ran hours later.
6Rolling It Out
We roll out by business importance: payments and orders first, where incident reviews hurt most, then the rest. Coverage per service and per topic, the share of records carrying the full header set, goes on a dashboard that leadership sees, which keeps it moving. New services get the standard by default from templates, so the gap only shrinks. After the first few incidents resolved with the lookup tool, we share them as examples, because a visible win does more for adoption than a mandate.
7Follow-up questions
Why both correlation id and causation id?
The correlation id groups every event from one user action, so we can pull the whole set at once. The causation id points to the direct parent, so we can rebuild the order of steps, which matters when one event fans out to many.
What about tail-based sampling?
Tail sampling keeps a trace after seeing it, for example every trace with an error. It catches more interesting traces but requires a collector tier that buffers all spans first, which at this volume is itself expensive. I would use it for selected flows, not across the board.
How do you handle services that cannot change soon?
A proxy or a stream processor can add missing ids at the boundary, but the real fix is the starter. We list those services, agree dates with their owners and track them on the coverage dashboard.
8Conclusion
In this answer, we saw that following events needs two things: cheap metadata on every event and sampled traces where they are worth the cost. We defined a small header set based on CloudEvents with correlation, causation and trace context, made the platform's starters add it in every language, sampled by flow importance while avoiding high-cardinality attributes, built a lookup by event id for incidents, and rolled it out by business importance with visible coverage.
Open with
I would separate metadata from tracing. Every event gets a small mandatory header set: a unique event id, the event type and version, the source service, a correlation id for the user action, a causation id for the event that triggered it, and W3C trace context.
Then, if they want more
I would base the names on the CloudEvents Kafka binding rather than invent our own, and document them in every event contract. The platform makes this the default: client configurations and starters in each of the five languages add the headers and propagate context automatically, and CI checks the contracts, because 300 teams will not do it consistently by hand.
Tracing every record at 2 million per second is too expensive, so sampling is by flow: 100 percent for critical flows like payments and a small head-based rate such as 0.1 percent for high-volume streams, with no high-cardinality span attributes.
For incidents, which are usually about one event, I would provide a lookup tool that finds an event by id or correlation id across topics and shows what each consumer did, from structured logs the starters write. That covers unsampled events too.
Rollout goes by business importance, with coverage per service on a dashboard and new services getting it from templates.
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 "What standard would you set for event metadata and tracing, and how would you roll it out?": https://scrivio-interview-library.netlify.app/spring-boot/kafka-clients-in-depth/80d50e5b79/