{"id":13485718,"url":"https://github.com/Meituan-Dianping/Leaf","last_synced_at":"2025-03-27T19:31:41.742Z","repository":{"id":37285345,"uuid":"161296037","full_name":"Meituan-Dianping/Leaf","owner":"Meituan-Dianping","description":"Distributed ID Generate Service","archived":false,"fork":false,"pushed_at":"2023-07-18T10:13:29.000Z","size":149,"stargazers_count":6547,"open_issues_count":96,"forks_count":1853,"subscribers_count":168,"default_branch":"master","last_synced_at":"2025-03-20T18:13:52.320Z","etag":null,"topics":["distributed-id-generator","leaf"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Meituan-Dianping.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-12-11T07:41:35.000Z","updated_at":"2025-03-18T03:00:51.000Z","dependencies_parsed_at":"2023-01-29T08:01:04.036Z","dependency_job_id":"7c2e631b-4590-4e07-8bae-0d564ad88430","html_url":"https://github.com/Meituan-Dianping/Leaf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meituan-Dianping%2FLeaf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meituan-Dianping%2FLeaf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meituan-Dianping%2FLeaf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Meituan-Dianping%2FLeaf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Meituan-Dianping","download_url":"https://codeload.github.com/Meituan-Dianping/Leaf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245910882,"owners_count":20692512,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distributed-id-generator","leaf"],"created_at":"2024-07-31T18:00:30.471Z","updated_at":"2025-03-27T19:31:41.216Z","avatar_url":"https://github.com/Meituan-Dianping.png","language":"Java","funding_links":[],"categories":["项目","Projects","Java","中间件","分布式开发"],"sub_categories":["数据库","Database"],"readme":"# Leaf\n\n\u003e There are no two identical leaves in the world.\n\u003e\n\u003e ​               — Leibnitz\n\n[中文文档](./README_CN.md) | [English Document](./README.md)\n\n## Introduction\n\nLeaf refers to some common ID generation schemes in the industry, including redis, UUID, snowflake, etc.\nEach of the above approaches has its own problems, so we decided to implement a set of distributed ID generation services to meet the requirements.\nAt present, Leaf covers Meituan review company's internal finance, catering, takeaway, hotel travel, cat's eye movie and many other business lines. On the basis of 4C8G VM, through the company RPC method, QPS pressure test results are nearly 5w/s, TP999 1ms.\n\nYou can use it to encapsulate a distributed unique id distribution center in a service-oriented SOA architecture as the id distribution provider for all applications\n\n## Quick Start\n\n### Leaf Server\n\nLeaf provides an HTTP service based on spring boot to get the id\n\n#### run Leaf Server\n\n##### build\n\n```shell\ngit clone git@github.com:Meituan-Dianping/Leaf.git\ncd leaf\nmvn clean install -DskipTests\ncd leaf-server\n```\n\n##### run\n###### maven\n\n```shell\nmvn spring-boot:run\n```\n\nor \n###### shell command\n\n```shell\nsh deploy/run.sh\n```\n\n##### test\n\n```shell\n#segment\ncurl http://localhost:8080/api/segment/get/leaf-segment-test\n#snowflake\ncurl http://localhost:8080/api/snowflake/get/test\n```\n\n#### Configuration\n\nLeaf provides two ways to generate ids (segment mode and snowflake mode), which you can turn on at the same time or specify one way to turn on (both are off by default).\n\nLeaf Server configuration is in the leaf-server/src/main/resources/leaf.properties\n\n| configuration             | meaning                          | default |\n| ------------------------- | ----------------------------- | ------ |\n| leaf.name                 | leaf service name                  |        |\n| leaf.segment.enable       | whether segment mode is enabled             | false  |\n| leaf.jdbc.url             | mysql url                 |        |\n| leaf.jdbc.username        | mysql username                 |        |\n| leaf.jdbc.password        | mysql password                   |        |\n| leaf.snowflake.enable     | whether snowflake mode is enabled         | false  |\n| leaf.snowflake.zk.address | zk address under snowflake mode      |        |\n| leaf.snowflake.port       | service registration port under snowflake mode |        |\n\n### Segment mode \n\nIn order to use segment mode, you need to create DB table first, and configure leaf.jdbc.url, leaf.jdbc.username, leaf.jdbc.password\n\nIf you do not want use it, just configure leaf.segment.enable=false to disable it.\n\n```sql\nCREATE DATABASE leaf\nCREATE TABLE `leaf_alloc` (\n  `biz_tag` varchar(128)  NOT NULL DEFAULT '', -- your biz unique name\n  `max_id` bigint(20) NOT NULL DEFAULT '1',\n  `step` int(11) NOT NULL,\n  `description` varchar(256)  DEFAULT NULL,\n  `update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n  PRIMARY KEY (`biz_tag`)\n) ENGINE=InnoDB;\n\ninsert into leaf_alloc(biz_tag, max_id, step, description) values('leaf-segment-test', 1, 2000, 'Test leaf Segment Mode Get Id')\n```\n### Snowflake mode \n\nThe algorithm is taken from twitter's open-source snowflake algorithm.\n\nIf you do not want to use it, just configure leaf.snowflake.enable=false to disable it.\n\nConfigure the zookeeper address\n\n```\nleaf.snowflake.zk.address=${address}\nleaf.snowflake.enable=true\nleaf.snowflake.port=${port}\n```\n\nconfigure leaf.snowflake.zk.address in the leaf.properties, and configure the leaf service listen port leaf.snowflake.port.\n\n### monitor page\n\nsegment mode: http://localhost:8080/cache\n\n### Leaf Core \n\nOf course, in order to pursue higher performance, you need to deploy the Leaf service through RPC Server, which only needs to introduce the leaf-core package and encapsulate the API that generates the ID into the specified RPC framework.\n\n#### Attention\nNote that leaf's current IP acquisition logic in the case of snowflake mode takes the first network card IP directly (especially for services that change IP) to avoid wasting the workId\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMeituan-Dianping%2FLeaf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMeituan-Dianping%2FLeaf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMeituan-Dianping%2FLeaf/lists"}