Quick revision
The short answer
On Kubernetes, services write JSON to stdout and stderr, and a node agent collects it; there are no file appenders inside containers. On VMs and legacy servers, services write local rolling files with strict size caps, and an agent on the host ships them; no file is ever unbounded. All environments use one structured format with the same required fields, retention and access are defined centrally, and we test what happens when the log backend is down: what buffers, what is dropped, and who is alerted.
What to remember
In this answer, we designed logging for a mixed estate around one structured JSON format with required fields that is the same everywhere. Kubernetes services write to stdout and stderr and a node agent collects them, with no file appenders in containers. VMs and legacy servers write capped local rolling files shipped by a host agent, never unbounded files. Retention and access are defined centrally in the backend, and we tested what buffers, what drops and who is alerted when the log backend is down.
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.
On Kubernetes, services write JSON to stdout and stderr, and a node agent collects it; there are no file appenders inside containers. On VMs and legacy servers, services write local rolling files with strict size caps, and an agent on the host ships them; no file is ever unbounded. All environments use one structured format with the same required fields, retention and access are defined centrally, and we test what happens when the log backend is down: what buffers, what is dropped, and who is alerted.
Why this question is asked
Mixed estates are normal: new services run on Kubernetes, some workloads stay on VMs for licensing or hardware reasons, and a few legacy servers run applications nobody wants to touch. If each environment logs its own way, investigations stop at environment boundaries and every new service reinvents its logging. Interviewers ask this design question to see whether we can set one standard that respects the real differences between environments. In this answer, we will define what stays the same everywhere, design the Kubernetes path, design the VM and legacy path, set retention and access centrally, and plan for the day the log backend fails.
1What Must Be the Same Everywhere
The part of the standard that crosses environments is the format and the fields, not the transport. Every service writes one JSON object per line, with a fixed set of required fields, so that a search for one trace id works across a pod, a VM and a legacy server. For Spring Boot 3.4 and later, structured logging gives this with logging.structured.format.console set to ecs or logstash; older services use a JSON encoder in their Logback configuration.
| Field | Example | Why |
|---|---|---|
| timestamp | 2026-11-05T10:42:01.317Z | UTC, millisecond precision, sortable |
| level | ERROR | filtering and alerting |
service.name | payments | who wrote it |
service.version | 4.12.0 | ties lines to a release |
| environment | prod-eu | separates prod from test |
| host or pod | payments-7d9f-x2k4 | finds the instance |
traceId, spanId | 4bf92f35..., 00f067aa... | correlation across services |
| message, logger | card declined, c.a.pay.Auth | what happened and where |
2Kubernetes: stdout in JSON, Collected by a Node Agent
In a container, the service writes to stdout and stderr only. The container runtime stores that stream in a file on the node, and a log agent running as a DaemonSet, one pod per node such as Fluent Bit or the OpenTelemetry Collector, tails those files, adds Kubernetes metadata like namespace, pod and labels, and ships the lines to the central backend.
We forbid file appenders inside containers for concrete reasons. A file inside the container disappears when the pod is replaced, which is exactly when we need it. It uses the pod's ephemeral storage, and a busy service can fill it and get the pod evicted. And it needs a sidecar or a shared volume to ship, which is more moving parts than the platform's own mechanism. The kubelet already rotates container logs (by default at 10 MB, keeping a few files; check your cluster's settings), so the service does not need to rotate anything.
3VMs and Legacy Servers: Capped Local Files and a Host Agent
On a VM there is no platform capturing stdout for us, so services write to a local rolling file, for example /var/log/payments/app.log, in the same JSON format. Every file appender must have three limits: a maximum file size such as 50 MB, a maximum history such as 7 days, and a total size cap such as 2 GB, so that the worst case of disk use is known in advance. An agent installed on the host tails the files and ships them, with its position saved so a restart does not lose or repeat lines.
Legacy servers are where compromises happen. An old application may write plain text, use log4j 1 or java.util.logging, or log to a fixed file we cannot change. There we still apply the parts we can: we add size caps through logrotate if the application cannot rotate, we parse its format in the agent into the standard fields, and we add service.name and environment in the agent's configuration. The rule "never unbounded" applies to legacy too; a disk filling up on a server nobody understands is the worst kind of incident.
- Shared formatJSON lines, required fields, UTC, trace ids
- Kubernetesstdout/stderr, kubelet rotation,
DaemonSetagent - VMslocal rolling file with size, history and total caps; host agent
- Legacy serverslogrotate caps, agent parses into the standard fields
- Central backendretention and access defined once
5 layers, from the top down. Step through them one at a time.
4Retention and Access, Defined Centrally
Retention and access are properties of the data, not of the environment, so the platform team defines them once in the backend. For example: 14 days for application logs, 30 days for warnings and errors, and audit logs on their own channel with retention set by compliance. Local files on VMs are only a buffer, kept a few days, not the system of record.
Access follows ownership: teams read logs of their own services, production access is audited, and fields that must never appear, such as tokens and personal data, are defined in the same standard. Because all environments ship to the same backend with the same fields, one set of rules covers the whole estate.
5Testing Behaviour When the Log Backend Is Down
The last part of the design is the failure mode, and we test it rather than assume it. We take the backend away in a test environment for 30 minutes and watch each path. On Kubernetes, the agent buffers to memory or disk and retries; the service is unaffected because it only writes to stdout, but the kubelet keeps rotating, so if the outage lasts longer than the node keeps files, the oldest lines are lost. On VMs, the files keep growing up to their caps while the agent waits, then the oldest archives are deleted.
So for each path we write down what is buffered, for how long, what is dropped first and who gets alerted: an alert on agent backlog or dropped records, and an alert on the backend's ingest rate falling. The design is complete when the answer to "the log backend is down for an hour, what happens?" is written, tested and acceptable, and when the answer never includes "the services slow down".
6Follow-up questions
Why not use a sidecar container to ship logs on Kubernetes?
A sidecar per pod multiplies agents, memory and configuration across thousands of pods, and still needs the application to write to a shared file. A node-level DaemonSet agent reading container stdout handles every pod on the node with one process. Sidecars are useful only for special cases, such as an application that can only write to a file.
Should the application send logs directly to the backend over the network?
Generally no. It couples the service to the backend's availability and latency, and a slow backend then blocks or drops inside the application. Writing locally and letting an agent ship keeps buffering and retries outside the request path. An application-level appender is acceptable only for small, non-critical cases.
How do we keep stack traces from becoming many separate lines?
With JSON logging, the stack trace is a field inside one JSON object, so it stays one record. With plain-text logs, agents need multiline rules to join lines, which are fragile. This is one more reason the standard requires structured logging everywhere.
7Conclusion
In this answer, we designed logging for a mixed estate around one structured JSON format with required fields that is the same everywhere. Kubernetes services write to stdout and stderr and a node agent collects them, with no file appenders in containers. VMs and legacy servers write capped local rolling files shipped by a host agent, never unbounded files. Retention and access are defined centrally in the backend, and we tested what buffers, what drops and who is alerted when the log backend is down.
Open with
I would separate what must be the same from what can differ. The same everywhere is the format: JSON lines with required fields such as a UTC timestamp, level, service name and version, environment, host or pod, trace and span ids, logger and message, so one search works across every environment.
Then, if they want more
On Kubernetes, services log only to stdout and stderr, in that JSON, and a DaemonSet agent such as Fluent Bit or the OpenTelemetry Collector collects the container logs and adds pod metadata. I would not allow file appenders in containers, because the files vanish with the pod, use ephemeral storage and can get the pod evicted.
On VMs, services write local rolling files in the same format, always with a size limit, a history limit and a total size cap, and a host agent ships them. On legacy servers I apply what I can: logrotate for caps, and the agent parses their format into the standard fields.
Retention and access are defined once, centrally, in the backend, with audit logs on their own channel. Finally, I would test a backend outage in a test environment and write down for each path what is buffered, for how long, what is dropped first, and which alerts fire, and make sure services never slow down because of it.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 3.4
- 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
- Spring Boot reference
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 "Define where and how logs are written for services running on Kubernetes, VMs and a few...": https://scrivio-interview-library.netlify.app/spring-boot/boot-logging/9cd72dccbd/