# meituan-dianping/leaf

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/meituan-dianping-leaf).**

6,730 stars · 1,875 forks · Java · apache-2.0

## Links

- GitHub: https://github.com/Meituan-Dianping/Leaf
- awesome-repositories: https://awesome-repositories.com/repository/meituan-dianping-leaf.md

## Topics

`distributed-id-generator` `leaf`

## Description

Leaf is a distributed unique ID generation system that provides two distinct modes for producing identifiers across multiple application instances without central coordination. It offers both a database-backed segment mode, which allocates blocks of IDs from a database table and caches them in memory for high throughput, and a Snowflake-style mode that combines timestamps, worker identifiers, and sequence counters to produce time-sortable unique IDs.

The system distinguishes itself by offering dual-mode generation through a single RESTful endpoint, allowing applications to choose between segment-based allocation for maximum throughput or Snowflake-style generation for time-ordered IDs with minimal persistence. Worker identity coordination ensures no duplicate IDs across distributed nodes, while the segment mode's in-memory caching minimizes per-request database calls. A web-based monitoring dashboard provides visibility into the current state of ID segment caches per business tag, helping operators track consumption.

The system supports globally unique identifier management across services and data centers, with both generation modes designed for high-performance, low-latency operation. It provides a stateless HTTP endpoint that any HTTP client can call to obtain unique identifiers for specific business tags, making integration straightforward for microservice architectures.

## Tags

### Part of an Awesome List

- [Database Segment Allocators](https://awesome-repositories.com/f/awesome-lists/devtools/unique-id-generation/database-segment-allocators.md) — Reserves and hands out blocks of unique IDs from a database to avoid per-request round-trips.
- [Database Tools](https://awesome-repositories.com/f/awesome-lists/data/database-tools.md) — Distributed ID generation service.

### Data & Databases

- [Unique Identifier Generators](https://awesome-repositories.com/f/data-databases/data-management/unique-identifier-generators.md) — Assigns IDs that are unique across services, data centers, or geographic regions without central coordination.
- [Distributed Identifier Generators](https://awesome-repositories.com/f/data-databases/data-management/unique-identifier-generators/distributed-identifier-generators.md) — Generates large volumes of unique, non-colliding identifiers across distributed instances without central coordination.
- [Batch ID Caches](https://awesome-repositories.com/f/data-databases/in-memory-caches/batch-id-caches.md) — Caches blocks of pre-allocated IDs in memory for high-throughput local allocations.
- [Segment Preallocation Strategies](https://awesome-repositories.com/f/data-databases/in-memory-databases/segment-preallocation-strategies.md) — Preallocates ID ranges in a database table and serves them from memory to reduce per-request writes.
- [Segment Caching Refills](https://awesome-repositories.com/f/data-databases/in-memory-caches/batch-id-caches/segment-caching-refills.md) — Reserve a range of IDs in a database table and serve them from memory, refilling the range when exhausted to reduce database load. ([source](https://github.com/Meituan-Dianping/Leaf#readme))

### Networking & Communication

- [Snowflake ID Compositions](https://awesome-repositories.com/f/networking-communication/distributed-systems-p2p/distributed-computing/deterministic-id-generation/snowflake-id-pagination/snowflake-id-compositions.md) — Composes 64-bit time-sortable IDs from timestamp, worker ID, and sequence counter.
- [Distributed ID Generators](https://awesome-repositories.com/f/networking-communication/distributed-systems-p2p/distributed-computing/distributed-id-generators.md) — Generates large volumes of unique, non-colliding identifiers across multiple application instances.
- [Dual-Mode ID Generators](https://awesome-repositories.com/f/networking-communication/distributed-systems-p2p/distributed-computing/distributed-id-generators/dual-mode-id-generators.md) — Offers both segment-based and Snowflake-style ID generation through a single endpoint.
- [High-Throughput ID Generators](https://awesome-repositories.com/f/networking-communication/distributed-systems-p2p/distributed-computing/distributed-id-generators/high-throughput-id-generators.md) — Delivers unique IDs at scale without central coordination, supporting both segment and timestamp-based schemes.
- [Snowflake ID Generators](https://awesome-repositories.com/f/networking-communication/distributed-systems-p2p/distributed-computing/distributed-id-generators/snowflake-id-generators.md) — Produces time-ordered unique IDs using timestamp, worker ID, and sequence counter.
- [ZooKeeper Worker Assignments](https://awesome-repositories.com/f/networking-communication/distributed-systems-p2p/distributed-computing/distributed-id-generators/snowflake-id-generators/zookeeper-worker-assignments.md) — Produce time-ordered unique IDs using a worker ID assigned through ZooKeeper and a local timestamp-based algorithm. ([source](https://github.com/Meituan-Dianping/Leaf#readme))

### Software Engineering & Architecture

- [Millisecond Clock Sequences](https://awesome-repositories.com/f/software-engineering-architecture/causal-ordering-timestamps/millisecond-clock-sequences.md) — Generates sequence numbers that reset per millisecond for unique, ordered IDs within the same timestamp.
- [Master-Worker Coordination](https://awesome-repositories.com/f/software-engineering-architecture/distributed-coordination-systems/task-coordinations/master-worker-coordination.md) — Uses coordination mechanisms to assign unique worker identities at startup.
- [Worker Identity Assignments](https://awesome-repositories.com/f/software-engineering-architecture/distributed-coordination-systems/task-coordinations/master-worker-coordination/worker-identity-assignments.md) — Assigns unique worker identities at startup via coordination to prevent duplicate IDs across nodes.

### Web Development

- [ID Services](https://awesome-repositories.com/f/web-development/high-performance-web-services/id-services.md) — Provides a low-latency, scalable endpoint for obtaining unique identifiers under load.
- [Time-Sortable](https://awesome-repositories.com/f/web-development/high-performance-web-services/id-services/time-sortable.md) — Providing identifiers that naturally sort by creation time, enabling efficient range queries and ordered storage.
