Quick revision
The short answer
A Kafka appender sends from inside the application, so when the brokers are down, sends block on metadata or a full buffer, and every request thread that logs blocks with them until thread pools run out and pods hang. Whether an appender blocks or drops depends on settings such as synchronous sending, max.block.ms and queue policy, which differ between Log4j2 and Logback appenders. The fix is that logging must never take down the service: write to stdout or local files and let an out-of-process shipper buffer and retry, or wrap any remaining Kafka appender in a non-blocking async appender with a drop policy, alerts on drops and the Kafka client's own logs kept out of it.
What to remember
In this answer, we followed a Kafka outage into 40 services: the producer inside each appender blocked on metadata and full buffers, Log4j2's synchronous sending waited for acknowledgements, request threads slept inside logging calls and pods hung. We saw that block or drop is decided by producer settings, appender options and async wrappers together. We redesigned shipping so applications write to stdout or local files and an external shipper buffers to disk and retries, and for teams keeping an in-process appender we made it non-blocking with a drop policy, quick timeouts, separate handling of the Kafka client's own logs and alerts on dropped events.
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.
A Kafka appender sends from inside the application, so when the brokers are down, sends block on metadata or a full buffer, and every request thread that logs blocks with them until thread pools run out and pods hang. Whether an appender blocks or drops depends on settings such as synchronous sending, max.block.ms and queue policy, which differ between Log4j2 and Logback appenders. The fix is that logging must never take down the service: write to stdout or local files and let an out-of-process shipper buffer and retry, or wrap any remaining Kafka appender in a non-blocking async appender with a drop policy, alerts on drops and the Kafka client's own logs kept out of it.
Why this question is asked
Logging is supposed to be a passive observer of the application. This incident turns that upside down: an outage in a system that only stores logs became an outage of 40 services that serve customers. Interviewers like the scenario because it tests whether we understand what a Kafka producer does when the brokers are down, and whether we treat the log pipeline as a dependency with failure modes. In this answer, we will recap how a Kafka producer sends records, follow the chain from broker outage to hung pods, look at the settings that decide blocking or dropping, redesign log shipping, and harden the in-process option for teams that keep it.
1A Quick Recap of How a Kafka Producer Sends
A Kafka appender is a logging appender that wraps a Kafka producer, the client object that writes records to a topic. When we call send(), the producer first needs metadata, the map of which broker leads each partition of the topic. If it does not have fresh metadata, it fetches it, and send() waits up to max.block.ms, 60 seconds by default, for that to succeed. The record then goes into an in-memory buffer, sized by buffer.memory, 32 MB by default, from which a background thread sends batches to the brokers. If the buffer is full, send() waits for space, again up to max.block.ms.
An appender may also wait for the broker's acknowledgement of each record before returning. Log4j2's Kafka appender does this by default, with its syncSend option set to true, so every logging call waits for a round trip to Kafka (check your version). Logback has no built-in Kafka appender; the commonly used third-party appender offers asynchronous and blocking delivery strategies, so its behaviour depends on how it was configured.
2From Broker Outage to Hung Pods
Now follow the outage. The brokers become unreachable. Each logging call on a request thread reaches the appender, which calls send(). With synchronous sending, the call waits for an acknowledgement that never comes, until a timeout. With asynchronous sending, the buffer slowly fills with records that cannot be delivered, and once it is full, every send() waits up to 60 seconds for space. Metadata refreshes fail too, and they also block for max.block.ms.
Meanwhile requests keep arriving. Every request thread that logs anything now sleeps inside the appender. Tomcat's default pool of 200 threads fills up with sleeping threads, new requests queue and then time out, and health checks, which also log or need a free thread, fail. Kubernetes restarts the pods, and the new pods hit the same wall. Latency rose sharply first, and then pods hung: exactly the symptoms in the question.
6 messages in order. Play them, or step through them one at a time.
Each logging call can now cost up to the producer's blocking timeout.
3The Settings That Decide: Block or Drop
Every in-process network appender has to answer one question: when the destination cannot keep up, does the caller wait, or is the event dropped? The answer is spread across settings at three levels. At the producer level there are max.block.ms, buffer.memory, delivery.timeout.ms and acks. At the appender level there is synchronous versus asynchronous sending, and for Log4j2 the syncSend option. At the wrapper level, if the appender is wrapped in an async appender, there are the queue size and whether a full queue blocks or discards: Logback's AsyncAppender blocks when full unless neverBlock is true, and Log4j2's Async appender blocks by default unless blocking is false or a discarding queue-full policy is set.
In our incident, the defaults chained together into 'wait'. A safe design needs 'drop' at every level that touches a request thread.
| Layer | Setting | Safe choice for logs |
|---|---|---|
| Kafka producer | max.block.ms (default 60000) | small, such as 0 to 100 ms |
| Kafka producer | buffer.memory (default 32 MB) | bounded; accept loss when full |
| Log4j2 Kafka appender | syncSend (default true) | false |
| Async wrapper | Logback neverBlock / Log4j2 blocking | never block the caller |
| Kafka client loggers | routed into the same appender? | no: separate appender, additivity off |
4Redesign: Take Delivery Out of the Process
The robust answer is to stop delivering logs over the network from inside the application. Services write structured JSON to stdout, in Kubernetes, or to a rotated local file, on virtual machines. A shipper running outside the application, such as Fluent Bit, Vector or the OpenTelemetry Collector, reads those logs and sends them to Kafka or to the log platform. Good shippers buffer to disk, so a Kafka outage of an hour simply means a backlog that drains afterwards, and they retry with back-off.
Notice what this does to the failure. The application's write to stdout is local and fast whatever Kafka is doing. If the outage outlasts the shipper's disk buffer, the shipper drops the oldest logs and reports it, and customers notice nothing. The log pipeline's failures stay in the log pipeline. This is also easier to operate: one shipper configuration per cluster instead of 40 Kafka client configurations embedded in application logging files.
5If the In-Process Appender Stays
Some teams have reasons to keep a Kafka appender, such as an environment with no shipper available. Then it must be configured to fail by dropping. We wrap it in an async appender with a bounded queue that never blocks, configure the producer itself to give up quickly, and give the Kafka client's own loggers a separate destination so the appender never logs into itself.
The last block matters more than it looks. When brokers are down, the Kafka client logs connection warnings. If those warnings flow into the Kafka appender, each failed send produces more logs to send, which in the worst case recurses or deadlocks inside the client. Sending the client's logs to the console breaks that cycle.
Finally, dropping must be visible. We alert on dropped events, so that 'we lost 3 percent of logs for 20 minutes' is a known, measured fact rather than a gap someone finds during an investigation.
6Follow-up questions
How would you measure how many log events were dropped?
At several points. Shippers export metrics for discarded and failed records, which we alert on. Inside the application, a wrapper or custom appender can count events that an async queue rejected and publish the count as a Micrometer counter, since the stock async appenders do not all expose one; Log4j2 can also route rejected events to an error appender. End to end, adding a per-instance sequence number to each event lets the log store detect gaps. Check your appender versions for what they expose.
Is it acceptable to lose logs at all?
For operational logs, yes, within limits we state openly: logging is best effort, and keeping the service up is more important than keeping every DEBUG line. Records that must not be lost, such as audit or payment events, should not travel through the general log pipeline at all, but through a durable channel with its own guarantees.
Would a circuit breaker around the appender help?
It can, because after a few failures it stops trying and drops immediately instead of waiting each time. But it is extra code inside every application, while an out-of-process shipper gives the same isolation for free, so I would treat it as a stopgap.
7Conclusion
In this answer, we followed a Kafka outage into 40 services: the producer inside each appender blocked on metadata and full buffers, Log4j2's synchronous sending waited for acknowledgements, request threads slept inside logging calls and pods hung. We saw that block or drop is decided by producer settings, appender options and async wrappers together. We redesigned shipping so applications write to stdout or local files and an external shipper buffers to disk and retries, and for teams keeping an in-process appender we made it non-blocking with a drop policy, quick timeouts, separate handling of the Kafka client's own logs and alerts on dropped events.
Open with
The appender put Kafka on the request path. A Kafka producer needs metadata and buffer space before send returns, and when the brokers are down, it waits up to max.block.ms, 60 seconds by default, for both.
Then, if they want more
Log4j2's Kafka appender also sends synchronously by default and waits for an acknowledgement. So every request thread that logged something ended up sleeping inside the appender, Tomcat's thread pool filled up with sleeping threads, latency went up, and eventually health checks failed and pods hung or restarted into the same problem.
Whether an appender blocks or drops depends on several layers: the producer settings, the appender's own options, and the async wrapper's queue policy, and here the defaults all said wait. My redesign rule is that logging must never take down the service.
Services write JSON to stdout, or to rotated files on VMs, and an out-of-process shipper like Fluent Bit, Vector or the OpenTelemetry Collector sends to Kafka, buffering to disk and retrying during an outage, so the failure stays in the log pipeline.
If a team must keep the in-process appender, I would wrap it in a non-blocking async appender with a bounded queue, set syncSend to false and max.block.ms very low, and route the org.apache.kafka loggers to the console with additivity off so the client cannot log into its own appender.
And I would alert on dropped events, so losses are measured, and send audit events through a separate durable channel.
About this answer
- Last updated
- 12 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 official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
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 "A team added a Kafka appender to send logs straight from 40 services to the log...": https://scrivio-interview-library.netlify.app/java/java-logging/923b3442cb/