How We Built a High‑Performance Ad Monitoring Service with OpenResty
This article details the design and implementation of ADMonitor, a high‑availability, low‑latency advertising monitoring platform built on OpenResty, covering its architecture, data collection, processing, archiving, and performance outcomes.
Part.1 Initial State
At first the ad monitoring service was a simple client‑side reporting system that recorded exposure and click events, but it suffered from inaccurate data, limited processing capacity, burst‑traffic failures (Redis memory pressure), complex deployment, and low development efficiency.
Part.2 Architecture Based on OpenResty
We created ADMonitor to provide a stable, reliable, and highly available ad monitoring service.
2.1 Design Idea
The new workflow generates a unique monitoring link for each ad, attaches it to the original customer link, and makes both exposure and click requests depend on ADMonitor. Clients request exposure in parallel, while click requests are redirected through ADMonitor for a second‑hop jump.
2.2 Technical Selection
OpenResty was chosen because it operates at the network layer, offers powerful regex‑based routing, provides Lua coroutine‑driven event loops, and benefits from LuaJIT’s just‑in‑time compilation for high performance.
2.3 Implementation
2.3.1 Data Collection
Lua scripts handle request inspection, filtering, and pushing data to shared memory, avoiding extra network hops. Optimizations include enabling lua_code_cache, configuring DNS resolvers, tuning epoll settings (multi_accept, accept_mutex, worker_connections), and setting keepalive parameters.
2.3.2 Data Processing
Collected logs undergo ETL and counting. ETL normalizes logs, extracts meaningful fields, filters noise, and redirects data. Counting stores metrics in Redis and FluxDB, using connection pooling and clustering for reliability and time‑series query efficiency.
2.3.3 Data Archiving
Full data is archived via the company’s big‑data pipeline: online Flink and offline Hive ingest logs, then store them in Elasticsearch. Kafka handles streaming, and automated scripts monitor failures.
2.4 Other OpenResty Use Cases
Splitter: Lua scripts query RedisCluster for NodeJS server load, then perform circuit‑break, downgrade, and rate‑limit, reporting metrics to InfluxDB.
Lightweight Web Firewall: Using lua_resty_waf library with IP/URL/UA filtering and CC protection, extended to push alerts to InfluxDB.
Part.3 Summary
ADMonitor, built on OpenResty, delivers high availability, immediate response, decoupled modules, and robust data guarantees. Performance metrics show >99.9% exposure success and >99.8% click success, with throughput and latency meeting strict standards.
Mafengwo Technology
External communication platform of the Mafengwo Technology team, regularly sharing articles on advanced tech practices, tech exchange events, and recruitment.
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.
