How We Scaled an Ad‑Serving Engine 10× with Go and Microservices
This article details the five‑year evolution of a commercial advertising platform, the performance and architectural challenges it faced, the step‑by‑step Go‑based microservice reconstruction, and the resulting tenfold improvements in capacity, latency, and cost efficiency.
1. Commercial Advertising Overview
Typical ad platforms consist of DSP (Demand Side Platform) for advertisers and SSP (Supply Side Platform) for publishers, connected via the standard ADX protocol.
On the SSP side we have our own main media, large‑scale partners, and open‑platform content partners, while on the DSP side we integrate third‑party DSPs via ADX and operate our own self‑serve ad platform Lingxi with its ad server.
Our product line includes brand ads, guaranteed‑delivery ads, and performance ads. Brand and guaranteed ads serve large advertisers, while performance ads require complex strategies and algorithms to achieve maximum conversions at minimal cost.
2. Challenges Faced by the Ad Engine
Rapid traffic growth led to peak QPS of over one million by the end of 2021, exposing severe performance limits.
The online ad engine must respond within 200 ms; the legacy engine frequently timed out, wasting high‑quality traffic.
CPU‑intensive self‑serve ads and I/O‑intensive programmatic ads were tightly coupled, making the codebase complex and hard to optimize.
Legacy code contained many obsolete business logics, making changes risky.
3. Reconstruction Roadmap and Technology Selection
3.1 Reconstruction Goals and Plan
We adopted an incremental reconstruction approach, prioritizing modules that deliver the greatest business value while ensuring system stability. Milestones align with key advertising campaigns.
3.2 Architecture Upgrade
The new architecture decouples self‑serve ads from programmatic ads, improving maintainability.
3.3 Technical Stack
To meet high‑concurrency, low‑latency requirements, the new system is built with Golang and organized as microservices, allowing independent module reconstruction.
4. Language and Framework Selection
4.1 Why Choose Golang
High performance with native support for massive concurrency.
Goroutine‑based model excels at I/O‑bound tasks.
Rich ecosystem and mature middleware.
Strong typing simplifies development and maintenance.
Low learning curve and rapid onboarding.
Compiled to native code for fast execution.
Built‑in testing, benchmarking, and profiling tools.
High developer productivity.
4.2 Golang Concurrency Model Advantages
4.3 Basic Golang Framework
Instead of heavyweight frameworks like Spring, we use the lightweight Gin HTTP server together with protobuf for RPC, which better fits our performance needs.
4.4 Typical Golang Use Cases in the Ad Engine
Ad bidding follows a Future/Promise pattern: a single request concurrently contacts multiple DSPs via ADX, and goroutine‑based wait groups aggregate the bids, solving asynchronous I/O bottlenecks.
5. System Infrastructure
5.1 New Engine Architecture
The new engine routes I/O‑intensive programmatic traffic through an ADX service, while the bid_engine handles CPU‑intensive self‑serve ads. The adserver still ingests main‑site traffic but delegates self‑serve bidding to bid_engine.
5.2 Core Golang Components
5.3 Implementation Summary
Internal RPC uses HTTP + protobuf with a reverse‑proxy load balancer; external interfaces also support protobuf and JSON.
Configuration is managed via Apollo, with Golang client libraries.
Monitoring and alerting rely on Prometheus and Grafana, providing fast issue detection.
Built‑in rate limiting and circuit‑breaker libraries improve stability.
Large‑capacity KV stores (e.g., Codis) handle frequency capping and anti‑fraud data with sub‑5 ms latency; future options include Morpheus and Aerospike.
6. Reconstruction Outcomes
6.1 Performance and Capacity Gains
ADX service performance increased by ~10×.
SSP integration boosted system throughput by ~8×.
Self‑serve ad capacity grew over 10×, latency dropped below 20 ms.
Overall system capacity rose >5× while server costs fell >50%.
6.2 Product Capability Improvements
Post‑reconstruction, we rapidly delivered new features such as material optimization, fine‑grained traffic operations, and anti‑fraud capabilities, strengthening our commercial advertising offering.
6.3 Maintainability Enhancements
The decoupled architecture reduced code complexity, accelerated iteration speed, and allowed clearer division of development responsibilities.
6.4 Business Impact
The incremental approach enabled stable, low‑cost development while supporting major sales events (618, 11.11, 12.12) in 2021, delivering measurable revenue growth.
7. Future Plans
With the new engine meeting most current demands, we will focus on fine‑grained traffic optimization, collaborate closely with the algorithm team to improve self‑serve ad click‑through rates, and continue driving efficient monetization and revenue growth.
Cyber Elephant Tech Team
Official tech account of Cyber Elephant, a platform for the group's technology innovation, sharing, and communication.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.