In high-traffic systems, the true bottleneck is not always obvious. Here, an ad delivery service showed periodic CPU spikes that threatened future stability. Datadog Continuous Profiler analysis revealed a less visible but critical issue: excessive heap allocations caused by memory escape in Go. By refactoring with iterators introduced in Go 1.23, CPU usage was reduced by 57% and memory allocation by 99.4%. This article explains the diagnosis, the technical hypothesis, and the implemented solution.

Performance problems are rarely solved by blind optimization. In high-traffic microservices environments, every memory allocation matters. ABEMA’s ad delivery system experienced periodic CPU spikes. The goal was not only to stabilize the system but to prepare the architecture to support new features without degradation. The key was to observe accurately before changing anything.
The system exhibited:
Profiling revealed a single method concentrated both the largest CPU usage and the highest memory allocation. The problem was not the algorithm itself, but how it was implemented.

However, this solution introduced implicit mutability, which could create unwanted side effects for consumers of the code. It was efficient, but architecturally risky.
This approach made it possible to:
Instead of returning a filtered slice, the method returns an iterator that applies chained filters without creating temporary structures.

In high-volume systems, small implementation choices scale exponentially. The problem wasn’t the algorithm it was the hidden memory cost. Reducing memory escape not only improves technical metrics; it increases stability, scalability, and the capacity for future innovation,this case shows that proper observability combined with thoughtful architectural decisions can completely transform a system’s performance.