High-Throughput Ad Serving with Go, PostgreSQL and Redis Caching
Modern digital advertising systems operate under rigorous performance constraints. When a user navigates to a publisher's web property, the ad tag must query candidate campaigns, filter inventory according to slot geometry, enforce frequency capping, and return creative markup within single-digit milliseconds.
"In real-time advertising, latency is currency. A lightweight Go server backed by compound B-tree indexes and Redis candidate sets allows sub-2ms ad decisioning at scale."
Decoupled Impression & Click Tracking
A critical architectural pattern in ad serving is separating ad delivery from event tracking. When GET /ad?size=WxH returns a creative, the creative is encapsulated in an anchor pointing to the tracking URL (/track/click?c=<id>). The browser renders the <img> element, and only once the media asset has successfully loaded in the client does the ad tag dispatch the impression beacon to /track/impression?c=<id>.
This guarantees that impressions are never prematurely tallied if a user bounces before creative assets materialize or if network packet loss disrupts the payload delivery. Furthermore, strict client-side once-per-load guards prevent duplicate impression recording.
Campaign Quotas and IP Frequency Capping
To ensure high advertiser return-on-ad-spend (ROAS), the serving engine enforces daily impression quotas per campaign and an IP-based frequency cap (configurable via AD_FREQ_CAP_MAX per creative per client IP per 24 hours). This mitigates impression burnout and balances brand visibility across unique audiences.