At small scale, logging feels almost free.
Add a few lines. Ship the service. Search the logs when something breaks.
That works until the system gets large enough that every log line carries a cost. Each line has to be stored, indexed, queried, and paid for.
In a high-volume supply-chain environment, some services processed around 500M application transactions per day and over 1B at peak traffic. At that scale, logging stopped being a background detail. It became infrastructure.
Where this started
It started with our cloud bill. We looked at what we were spending and what we were forecasted to spend the next year, and logging stood out. Traffic was growing, we kept adding services, and every one of them streamed every log straight into BigQuery. Streaming is the most expensive way to get data in, and we were using it for everything.
Cost wasn't the only problem. Each service logged in its own format. The same request ID might be requestId in one service, req_id in another, and buried in a message string in a third. When something broke, whoever was on triage had to know each service's quirks before they could write a useful query, and those queries were slow because they were scanning and string-matching unstructured text.
Most of those logs were also low value. An error from a failing order is worth seeing right away. A success-path request and response payload that nobody looks at unless something else goes wrong is not. We were paying the same premium for both.
The question I kept coming back to was:
Does this log earn the cost of preserving and querying it this way?
The logging library
The first piece was a shared logging library for our Java services, both Spring Boot and Quarkus. It wraps SLF4J, so teams keep the logging API they already know, but every event comes out as structured JSON.
I made the JSON match the BigQuery table schema one to one. Whatever a service logs maps directly to a column someone can filter on later. Every event gets the same base fields:
- Service
- Log type
- Request type
- Correlation ID
- Severity
- Timing
- Status
- Payload
- Ingestion path
Teams can add their own fields on top for domain-specific data. Output goes through Logback and logstash-logback-encoder asynchronously, which kept logging off the request thread and gave us a small performance win too.
Deciding what streams
Every log type in the library is tagged as either stream or batch. That lives in one shared taxonomy, so individual services aren't making that call ad hoc.
Errors and exceptions always stream. High-volume success-path logs batch by default. If a team has a real reason to see something immediately, they can stream it, but they decide that up front. Batch latency is written down as part of each log type, so nobody finds out during an incident that the log they need is an hour behind.
The pipeline
Each region has two log routers that read the ingestion path off each event.
High-signal logs stream straight into BigQuery and show up within seconds. Low-signal logs get written to a Cloud Storage bucket instead. A BigQuery transfer job picks them up roughly every 15 minutes, and a scheduled query merges them into the same table the streamed logs land in.
So a batched log can take up to about an hour and a half to become searchable, but it ends up in the same table either way. Nobody has to know which path a log took to find it.
Rolling it out
I didn't want to flip a switch and hope. For each service we ran the old and new pipelines side by side and compared the output, and only turned the old one off once they matched.
I wrote most of the docs (the implementation guide, the batch design, and a contributing guide), held office hours for teams moving over, and built some review tooling that checks new logging code against the schema before it merges. A lot of that tooling came out of complaints from early adopters. If someone was confused or something was annoying to use, I treated it as a bug in the library.
What actually got it prioritized across teams was framing it as a cost problem. Once the numbers were in front of people, it went from "nice cleanup" to something teams were expected to adopt.
What broke
Dropped logs under load
Async logging can drop events if it falls behind, and I didn't want to find that out from a missing log in the middle of an incident. So we built a dropped-log metric before going live.
Load testing turned up about 6M dropped logs.
The async appender in logstash-logback-encoder sits on a Disruptor ring buffer, and the default size is 8192 events. During load test bursts, logs were coming in faster than the drain thread could ship them out. Once the buffer is full, new events just get dropped, and nothing tells you unless you're measuring it.
<appender name="ASYNC" class="net.logstash.logback.appender.LoggingEventAsyncDisruptorAppender">
<!-- 8192 is the default. When it fills, new events are dropped. -->
<ringBufferSize>8192</ringBufferSize>
<appender-ref ref="JSON" />
</appender>
We ran a lot of load tests after that. Drops only showed up in some of them, and only during synthetic bursts well above anything production actually sees.
The easy fix would have been to make the buffer bigger. I left it alone.
A bigger buffer helps with spikes but does nothing for throughput. If the drain is ever slower than steady traffic, you're still going to drop logs, just later, and with more of them sitting in memory when it happens.
Storage egress we didn't plan for
Batching brought the streaming bill down, but our Cloud Storage costs started climbing.
We had one bucket per region, so we'd made them regional buckets. The BigQuery datasets, though, were multi-regional. Every transfer from a regional bucket into a multi-regional dataset was paying egress, and at our volume that added up fast.
We switched the buckets to multi-regional and kept routing only one region's logs into each one. Same routing, no more egress charge.
Things that only show up when a team adopts it
When one of the bigger teams got ready to go live, I went through their design doc and found two problems.
They were logging exceptions without the exception:
// The stack trace is lost
log.error("Order lookup failed: " + e.getMessage());
// Pass the Throwable as the last argument so the stack trace is kept
log.error("Order lookup failed", e);
They also had a dependency exclusion that pulled out logback-classic. The library writes through Logback, so without it SLF4J has nothing to send logs to, and that service would have gone quiet.
Neither would have shown up in the library's own tests. Reviewing design docs for adopting teams ended up being part of the rollout after that.
What changed
Five services log through the library now, all into one table. Most of the volume moved to the batch path, and one of the larger teams is at 90% batched. Some queries got up to 90% faster, and people on triage can filter on the same fields no matter which service they're looking at.
The conversation around logging changed too. When someone adds a log now, the questions are more like:
-
Who's going to use this?
-
How fast do they need it?
-
Is it high signal or low signal?
-
What fields make it queryable?
-
What does it cost at production volume?
What I learned
The biggest lesson was simple: observability has a cost model.
Ignore that cost model, and the bill eventually becomes the architecture.
Good logging is not about emitting the most data. It is about preserving the right information, in the right shape, on the right path, for the right amount of time.
The right answer is not "log everything." It is not "log less" either.
The right answer is to make logs earn their place.