Designing Routing Keys for Sharding in an Order Platform
This article explains how to select and implement routing keys for database sharding in a food‑delivery order system, covering supported scenarios, single‑ and multi‑database strategies, hash‑based distribution for both user and merchant data, and practical flow diagrams to ensure balanced and efficient data access.
After splitting tables, the first problem is choosing a routing key that exists uniquely in each table; the article discusses selecting keys such as timestamps for archival data or business‑related identifiers.
Supported scenarios for a food‑delivery order platform are described from both consumer (C‑end) and merchant (B‑end) perspectives, emphasizing real‑time order status queries and merchant analytics.
Routing strategies are presented for single‑database and multi‑database environments: using the user_id hash modulo the number of tables, or extending the hash to select the appropriate database first and then the table.
Examples illustrate how to store orders by hashing user_id, how merchants can consume order messages from MQ and apply the same routing logic, and visual diagrams (omitted) show the complete data flow.
The article concludes with key points: design routing keys closely tied to business scenarios and ensure even data distribution.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
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.