Design and Implementation of the “Dayu” Business Gateway for Bilibili Membership Purchase

This article presents a comprehensive architectural analysis of Bilibili’s “Dayu” business gateway, detailing its motivations, design principles, async processing model, configurable pipelines, dynamic Ognl expressions, caching strategies, performance results, and practical lessons for backend developers.

High Availability Architecture
High Availability Architecture
High Availability Architecture
Design and Implementation of the “Dayu” Business Gateway for Bilibili Membership Purchase

Gateways have become a recurring topic in modern micro‑service and cloud‑native architectures. While traffic gateways (e.g., Nginx, Tengine) handle global load balancing and security, business gateways sit behind them to provide fine‑grained request routing, authentication, rate‑limiting, and service orchestration for specific business domains.

The article introduces Bilibili’s “Dayu” business gateway, built to address the growing complexity of the “Membership Purchase” platform. “Dayu” is not a one‑size‑all solution; it is a lightweight, business‑centric gateway that leverages Netty4 for asynchronous networking, Async Http Client for non‑blocking downstream calls, and Ognl for dynamic expression evaluation.

Async vs. Semi‑Async Processing – “Dayu” adopts a fully async, non‑blocking model for simple proxy scenarios (Direct mode). Requests arrive on Netty I/O threads, are queued to worker threads, and are handed off to a configurable Pipeline. The AggregatePipeline can split a request into parallel downstream calls, aggregate responses, and rewrite the final payload. For more complex use‑cases, a semi‑async mode is used where the pipeline waits for the longest downstream response before proceeding.

Configuration Format – All service interface definitions are stored as JSON schemas (referred to as “Schema”). A typical configuration maps a POST /helloworld endpoint to a downstream GET request, while more complex examples illustrate parallel calls with conditional dependencies and required sub‑requests. The JSON schema is loaded into memory at startup and refreshed in real time via Alibaba Canal binlog listeners or periodic polling.

Dynamic Routing with Ognl – Ognl expressions are embedded in the schema to enable conditional routing, header manipulation, and response rewriting. Example snippets show how a check field can direct traffic to different hosts based on request payload values, and how express statements can modify response fields or inject timestamps.

Caching Mechanism – “Dayu” provides a large‑grain cache layer with CacheGetPipeline and CacheSetPipeline. Cache keys are computed via Ognl (e.g., $request.itemsId), can be sharded into multiple segments to avoid hot‑key issues, and support optional compression. The pipeline automatically serves cached data when available, falling back to downstream calls otherwise.

Cache‑Circle Strategy – To mitigate cache‑stampede spikes, a “circle” mechanism pre‑emptively refreshes cache entries before expiration. TTL values are inspected in the Ognl context; if they fall within a configurable head‑tail window, an asynchronous circle request is triggered while normal traffic continues to read the still‑valid cache.

The implementation has been stress‑tested on a 4‑node 8C8G cluster, achieving ~80 k QPS with average latency of 60 ms, CPU utilization around 70 %, and error rates below 0.1 %.

Finally, the article includes a recruitment call for engineers interested in contributing to Bilibili’s fast‑growing e‑commerce platform.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

BackendMicroservicesConfigurationcachingAsync
High Availability Architecture
Written by

High Availability Architecture

Official account for High Availability Architecture.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.