Deploy as a central ID service so multiple backend servers can generate unique record IDs without database conflicts.
Use segment-based mode to reduce database write load in a high-traffic application.
Use Snowflake mode to generate timestamp-ordered unique IDs without any database dependency.
Embed the core library directly into an RPC service for maximum throughput beyond the HTTP API.
Segment mode requires a MySQL database with a specific schema, Snowflake mode requires ZooKeeper for server coordination.
Leaf is a Java service from Meituan-Dianping, a large Chinese food delivery and services company, that generates unique ID numbers for use across distributed systems. The name comes from a Leibnitz quote about snowflakes and leaves, and it addresses a specific problem: when many servers in a large application all need to create unique record identifiers at the same time, standard approaches like auto-incrementing database IDs break down because there is no single place to coordinate. Leaf solves this by acting as a central ID-issuing service that all other services can call. The service runs as an HTTP server built on Spring Boot. Any application that needs a new unique ID makes an HTTP request to Leaf and gets one back. The README mentions the system handles nearly 50,000 requests per second on a mid-range server, with response times under 1 millisecond for the 99.9th percentile, and that it covers multiple business lines within Meituan including payments, food delivery, and hotels. Leaf supports two different methods for generating IDs. The first is a segment-based approach that reserves a range of numbers in a MySQL database and hands them out in batches, reducing database load. The second is based on Twitter's Snowflake algorithm, which generates IDs by combining a timestamp, a server identifier, and a sequence number into a single 64-bit number, requiring no database but needing ZooKeeper to coordinate which server ID each instance gets. Setup involves cloning the repository, building with Maven, configuring a properties file with database or ZooKeeper connection details, and starting the server. The README also describes a lower-level integration path where you include the core library directly in an RPC server if you need higher performance than the HTTP interface provides. The project is open-source. The README is available in both Chinese and English.
← meituan-dianping on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.