Industry Insights 12 min read

How 58 Daojia Built a Scalable Real‑Time Messaging Platform: Architecture Deep Dive

This article dissects the design of 58 Daojia’s universal real‑time messaging platform, detailing the challenges of end‑to‑cloud, cloud‑to‑end, and end‑to‑end communication, the shortcomings of traditional HTTP and push solutions, and the optimized TCP, message‑bus, RPC, and protocol extensions that achieve scalability, reliability, and cross‑account chat.

Big Data and Microservices
Big Data and Microservices
Big Data and Microservices
How 58 Daojia Built a Scalable Real‑Time Messaging Platform: Architecture Deep Dive

Problem Statement and Challenges

The 58 Daojia logistics service needed three real‑time communication flows: (1) End‑to‑Cloud – drivers continuously reporting GPS locations; (2) Cloud‑to‑End – instant order push to drivers; (3) End‑to‑End – chat between users, merchants, and customer service. Key difficulties were ensuring message reachability in unreliable wireless environments and keeping the platform generic enough to stay decoupled from individual business lines.

Traditional Solutions and Their Limitations

End‑to‑Cloud (HTTP polling) typically used web‑servers that wrote directly to a database. This incurred high overhead from repeatedly creating short‑lived HTTP connections and limited throughput to only a few thousand requests per second.

Cloud‑to‑End (third‑party push services) relied on APNs, MiPush, etc., which could not guarantee real‑time delivery and often imposed rate limits. Self‑hosted MQTT services suffered from availability concerns.

End‑to‑End (combined approach) attempted to stitch the two methods together but still inherited the above drawbacks.

Optimized Real‑Time Messaging Platform

The platform abstracts drivers, users, merchants, and customer service as “online” entities and introduces several optimizations:

TCP Long‑Connection : Replaces HTTP polling with persistent TCP channels to reduce connection overhead.

Message Bus Decoupling : Uses a message‑queue (msg‑queue) to separate the messaging platform from business‑line app‑servers, allowing new business lines to add only a mapping between message type and queue topic.

RPC Interfaces for Cloud‑to‑End : Provides RPC endpoints so the platform can push messages without third‑party services, preserving decoupling.

State‑Based Delivery : Stores online/offline status in a high‑availability Redis cluster; only online users receive push, reducing unnecessary traffic.

Reliable Delivery Guarantees : Messages are first persisted to a database, the platform acknowledges the sender immediately, and a parallel delivery path attempts to push to the receiver. The receiver sends an application‑layer ACK; upon receipt, the platform deletes the stored message.

Failure Handling : Senders retry if they do not receive the platform’s acknowledgment; receivers deduplicate repeated messages, enabling a stateless server design.

Layered Architecture

The system consists of:

msg‑sdk embedded in the mobile app, exposing a clean API.

msg‑gate – a TCP gateway handling long‑connection management, basic encryption/compression, and initial defense.

msg‑logic – core business logic of the messaging platform.

Redis Cluster – stores user online status and the gateway to which each user is connected.

Database – persists offline messages.

Business side components include the mobile APP (using msg‑sdk), an MQ for “end‑to‑cloud” delivery, and app‑servers that consume MQ messages and use RPC to send “cloud‑to‑end” pushes.

Public Interfaces

For APP developers (msg‑sdk):

login / logout

c2s – client‑to‑server (end‑to‑cloud) messaging

c2c – client‑to‑client (end‑to‑end) messaging

get‑offline‑msg – fetch stored offline messages

on‑msg‑received – callback for incoming messages

For app‑servers:

s2c – server‑to‑client (cloud‑to‑end) messaging

Internal SDK‑platform interfaces (transparent to business): keepalive and c2c‑ack.

Cross‑Account Chat Support

To enable communication across different account domains (e.g., QQ vs. WangWang), the platform replaces a single UID key with a composite domain+uid or appid+uid. This introduces a minor coupling in the login logic (switch‑case on domain/appid) but keeps the overall design extensible.

Protocol Extensibility Design

Given the client‑server nature of mobile apps, the protocol uses a fixed‑length header plus a variable‑length body, with a command ID (cmd) to add new interfaces without breaking existing clients. For payload evolution, protobuf or similar extensible serialization is employed. Message bodies themselves are designed to be extensible (XML/JSON) to support rich features such as styled text, images, window shaking, or typing indicators while maintaining backward compatibility.

Distributed Architecture Considerations

The platform’s distributed design addresses scalability, load balancing, high availability, and consistency, though detailed diagrams were omitted in the source. The architecture relies on horizontal scaling of msg‑gate, msg‑logic, Redis, and the database, with the message bus providing loose coupling between components.

Key Takeaways

Use TCP long‑connections and a message bus to decouple business logic and achieve high‑throughput end‑to‑cloud delivery.

Provide RPC interfaces for cloud‑to‑end pushes, avoiding third‑party rate limits.

Persist messages to DB and employ application‑layer ACKs to guarantee delivery even in unstable wireless environments.

Implement offline storage and sender/receiver retry & deduplication mechanisms for stateless server operation.

Design protocols with fixed headers and extensible bodies (protobuf, XML/JSON) to allow seamless feature addition and backward compatibility.

Adopt a composite key (domain/appid + uid) to support cross‑account chat while keeping the platform largely agnostic to specific business domains.

Overall, the 58 Daojia real‑time messaging platform demonstrates how a well‑structured, decoupled architecture can meet demanding latency, reliability, and scalability requirements for logistics and on‑demand services.

distributed-systemsreal-time messagingbackend architectureMessage QueueProtocol Designcross-account chat
Big Data and Microservices
Written by

Big Data and Microservices

Focused on big data architecture, AI applications, and cloud‑native microservice practices, we dissect the business logic and implementation paths behind cutting‑edge technologies. No obscure theory—only battle‑tested methodologies: from data platform construction to AI engineering deployment, and from distributed system design to enterprise digital transformation.

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.