Quick revision
The short answer
Logback's AsyncAppender puts each event into a bounded BlockingQueue (256 slots by default) and a single worker thread takes events off the queue and passes them to the wrapped appender. discardingThreshold drops TRACE, DEBUG and INFO events when remaining capacity falls below it (20 percent by default) while keeping WARN and ERROR, neverBlock=true makes callers drop events instead of waiting on a full queue, and includeCallerData is false by default because caller data must be captured, expensively, on the calling thread. Events still queued at shutdown are lost unless the LoggerContext is stopped properly, which flushes for up to maxFlushTime; Spring Boot registers a shutdown hook that does this.
What to remember
In this answer, we saw that AsyncAppender puts events into a bounded queue, 256 by default, and a single worker thread writes them through the wrapped appender. discardingThreshold drops TRACE, DEBUG and INFO when free capacity falls below 20 percent of the queue by default, neverBlock=true drops instead of making callers wait when the queue is full, and includeCallerData is false by default because caller data must be captured on the calling thread. The MDC is copied into each event at enqueue time, and queued events are lost at shutdown unless the LoggerContext is stopped, which Spring Boot's shutdown hook does, flushing for up to maxFlushTime.
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.
Logback's AsyncAppender puts each event into a bounded BlockingQueue (256 slots by default) and a single worker thread takes events off the queue and passes them to the wrapped appender. discardingThreshold drops TRACE, DEBUG and INFO events when remaining capacity falls below it (20 percent by default) while keeping WARN and ERROR, neverBlock=true makes callers drop events instead of waiting on a full queue, and includeCallerData is false by default because caller data must be captured, expensively, on the calling thread. Events still queued at shutdown are lost unless the LoggerContext is stopped properly, which flushes for up to maxFlushTime; Spring Boot registers a shutdown hook that does this.
Why this question is asked
Asynchronous logging is the usual answer when logging I/O slows request threads: instead of each request thread waiting for a disk or network write, it hands the event to a queue and moves on. But the queue changes the guarantees we get. Events can be dropped, callers can still block, some information is no longer available, and events can be lost at shutdown. Interviewers ask about AsyncAppender's settings because each one is a decision about one of those trade-offs. In this answer, we will see how the appender works, then go through queueSize, discardingThreshold, neverBlock and includeCallerData with what each does under load, explain why the MDC is copied at enqueue time, and finish with shutdown.
1How AsyncAppender Works
AsyncAppender does not write anything itself. It wraps another appender, such as a file or console appender, and sits in front of it. When a request thread logs, AsyncAppender prepares the event for later processing and puts it into a bounded ArrayBlockingQueue. A single worker thread, created by the appender, takes events from the queue one by one and calls the wrapped appender, which does the actual formatting and writing.
So the request thread only pays for preparing the event and putting it in the queue, which takes microseconds, while the slow write happens on the worker thread.
2QueueSize and discardingThreshold
queueSize is the capacity of the queue, 256 events by default. It is the buffer that absorbs bursts: if the service suddenly logs 5,000 events in a second while the disk writes 2,000, the queue holds the difference until it fills.
discardingThreshold decides what happens as the queue gets full. When the remaining capacity drops below the threshold, AsyncAppender starts discarding events at TRACE, DEBUG and INFO, and keeps WARN and ERROR. The default threshold is one fifth of the queue size, so with the default queue of 256, once fewer than about 51 slots are free, INFO lines are silently dropped. The reason is to protect the important events: when the system is under pressure, warnings and errors matter more than routine information. Setting the threshold to 0 disables discarding, so every level is kept and callers block instead when the queue is full.
- Request thread logs an event
- Remaining capacity below discardingThreshold?YesNext checkNoPut in queue
- Level is INFO or lower?YesDrop the eventNoPut in queue
- Queue full?YesneverBlock: drop; else waitNoEnqueued
- Worker thread writes it via the wrapped appender
5 steps in order. Play them, or step through them one at a time.
3NeverBlock: Waiting Versus Dropping
When the queue is completely full, AsyncAppender has two choices. With the default neverBlock=false, the calling thread waits in put() until the worker frees a slot. That means no event is lost, but a request thread can be stuck behind a slow disk, which is the very latency problem async logging was supposed to solve. With neverBlock=true, AsyncAppender uses offer() instead, and if the queue is full the event is simply dropped, so request threads never wait for logging.
Which one is right depends on the service. For a latency-sensitive API, losing a few log lines during an extreme burst is usually better than stalling requests, so neverBlock=true is reasonable. For a batch job where every line matters and latency does not, blocking is fine.
4IncludeCallerData and the MDC
includeCallerData controls whether the appender captures caller data, the class, method, file and line number of the log call. Java gives this information only through a stack trace, and a stack trace only exists on the calling thread. So if a pattern uses %class or %line and includeCallerData is true, AsyncAppender must capture a stack trace on the request thread before queueing, which is expensive. That is why it is false by default; with it false, those conversion words print a question mark.
The same logic applies to everything that belongs to the calling thread. Before queueing, AsyncAppender calls prepareForDeferredProcessing on the event, which fixes the formatted message, the thread name and a copy of the MDC into the event. The worker thread runs much later, on a different thread, so without that copy it would see its own empty MDC, or worse, the MDC of whatever happened to run there.
5What Happens at Shutdown
Events in the queue exist only in memory. If the JVM exits while 300 events are still queued, those events are lost unless something drains the queue first. When the LoggerContext is stopped properly, AsyncAppender's stop method interrupts the worker and waits up to maxFlushTime, 1,000 milliseconds by default, for the remaining events to be written. Anything not written in that time is dropped.
So the important question is whether the context is stopped at all. Spring Boot registers a shutdown hook by default (logging.register-shutdown-hook=true) that stops the logging system when the JVM shuts down normally, for example on SIGTERM from Kubernetes. Without Spring Boot, Logback's <shutdownHook/> element in the configuration installs one. Neither helps with kill -9 or a JVM crash, which is a reason to keep important records out of logs that may still be in a queue.
6 messages in order. Play them, or step through them one at a time.
6Follow-up questions
Why must MDC values be copied when the event is queued?
Because the MDC is stored per thread, and the event is written later on the worker thread. If the event only pointed at the request thread's MDC, then by the time the worker formatted it, the request might have finished and cleared the MDC, or the thread might be handling another request with a different traceId. Logback avoids this by copying the MDC map into the event in prepareForDeferredProcessing before queueing, so each event carries a snapshot of the MDC as it was at the moment of the log call.
How do you know if AsyncAppender is dropping events?
Logback does not report each discarded event, so we have to look for it: compare the expected number of lines with what arrived, watch for gaps in INFO lines during load peaks, or wrap the appender with a small subclass that counts discards and exports a metric. If drops happen regularly, increase queueSize, reduce log volume, or make the wrapped appender faster.
Is a bigger queue always better?
No. A larger queue absorbs longer bursts, but it uses more memory, holds more events that can be lost at a crash, and hides a sustained mismatch between log rate and write speed for longer. If the disk cannot keep up on average, any queue eventually fills; the real fix then is less volume or faster output.
7Conclusion
In this answer, we saw that AsyncAppender puts events into a bounded queue, 256 by default, and a single worker thread writes them through the wrapped appender. discardingThreshold drops TRACE, DEBUG and INFO when free capacity falls below 20 percent of the queue by default, neverBlock=true drops instead of making callers wait when the queue is full, and includeCallerData is false by default because caller data must be captured on the calling thread. The MDC is copied into each event at enqueue time, and queued events are lost at shutdown unless the LoggerContext is stopped, which Spring Boot's shutdown hook does, flushing for up to maxFlushTime.
Open with
AsyncAppender wraps a real appender, like a file appender. When a thread logs, it prepares the event for deferred processing and puts it on a bounded ArrayBlockingQueue, 256 slots by default, and a single worker thread takes events off and calls the wrapped appender, so the slow I/O is off the request thread. discardingThreshold is about what to drop under pressure: when remaining capacity falls below it, which by default is a fifth of the queue, TRACE, DEBUG and INFO events are discarded and WARN and ERROR are kept.
Then, if they want more
Setting it to zero keeps everything. neverBlock decides what happens when the queue is completely full: by default the caller blocks until there's room, which brings the latency back; with neverBlock true, the event is dropped and the caller continues. includeCallerData is false by default because class, method and line need a stack trace captured on the calling thread, which is expensive, so with it off those fields print a question mark.
For the same reason the event copies the MDC, thread name and formatted message before it's queued. At shutdown, queued events are only in memory, so they're lost unless the logger context is stopped; then the appender drains for up to maxFlushTime, one second by default.
Spring Boot registers a shutdown hook that does that on a normal SIGTERM, but nothing helps on kill -9.
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 "How does Logback's AsyncAppender work? Explain queueSize, discardingThreshold...": https://scrivio-interview-library.netlify.app/java/java-logging/8d327a24b0/