Design and Implementation of GDP Streaming RPC Framework (Go Version of brpc Streaming)
The Go‑based GDP Streaming RPC framework extends Baidu’s internal brpc‑compatible RPC system with a high‑performance streaming transport that preserves message order, supports multiple concurrent streams per socket, offers customizable serialization and event‑driven handlers, and enables efficient large‑scale data transfers such as voice or replica synchronization, achieving comparable latency and throughput to the original C++ implementation.
GDP (Go Develop Platform) is an internal Baidu RPC framework that provides complete client and server capabilities for building APIs, web services, and backend applications. GDP Streaming RPC extends the basic RPC features with a streaming transport layer, offering a solution for large‑scale or continuously generated data transfers.
The framework addresses problems such as transmitting massive ordered data that cannot fit into a single RPC message, e.g., replica synchronization, voice data, or exporting millions of records. Streaming RPC enables processing records one by one, avoiding the need to wait for the entire payload.
Key design goals include:
Compatibility with brpc streaming protocol
Queryable stream state
Preserving order of sent and received messages while allowing parallel streams
Customizable serialization/deserialization
Support for multiple streams over a single socket connection
The framework defines several core concepts:
stream : a user‑level connection between client and service, transmitting messages in order.
message : the basic unit of data transfer.
stream connector : manages a socket and hosts multiple streams.
event : lifecycle events such as handshake success/failure, data processing, timeout, and stream closure.
handler : callback interface invoked on specific events.
request : encapsulates stream metadata and message payload.
The interaction model follows a three‑stage process: handshake, communication, and closure. A client creates a local stream, performs an RPC to establish the stream on the server, and receives a stream ID. Communication uses a bidirectional RPC protocol (strm) that allows simultaneous sending and receiving of messages.
When errors occur, either side can initiate a stream closure. The framework propagates the closure to all streams sharing the same socket, ensuring resources are released promptly.
Callback registration is handled via a Handler interface. Implementations provide custom logic for events such as handshake responses, timeouts, processing errors, and stream termination. Example definition:
type Handler interface {
Handle(context.Context, Stream, Request) error
}A practical case study replaces a brpc‑based voice transmission module with the Go streaming implementation. Performance tests show comparable success rates and latency, with small‑packet throughput reaching 25 k requests/s and CPU usage only ~20% higher than the original brpc.
In conclusion, the Go‑based GDP Streaming RPC offers a high‑performance, extensible alternative to C++ brpc, leveraging Go’s concurrency model and adhering to SOLID principles, making it suitable for large‑scale Baidu services.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
