A high-performance distributed sequence generator built with Java 8 and Spring Boot.
- High Performance: In-memory buffer with multi-level caching
- High Availability: Dual-database failover support
- Multi-Business Support: Configurable business types with different step sizes
- Set-Based Deployment: Support for distributed deployment across multiple sets
- Load Testing Isolation: Separate sequence ranges for load testing
- RESTful API: Simple HTTP-based interface
- Monitoring: Built-in health checks and metrics
- Java 8 or higher
- Maven 3.6+
- Clone the repository
- Navigate to the project directory
- Run the application:
mvn spring-boot:runThe application will start on http://localhost:8080/sequence-gen
curl -X POST http://localhost:8080/sequence-gen/api/v1/sequences/generate \
-H "Content-Type: application/json" \
-d '{
"businessType": "ORDER",
"source": "WEB"
}'curl -X POST http://localhost:8080/sequence-gen/api/v1/sequences/batch \
-H "Content-Type: application/json" \
-d '{
"businessType": "PAYMENT",
"batchSize": 10,
"source": "MOBILE"
}'curl http://localhost:8080/sequence-gen/api/v1/admin/statusConfigure business types in application.yml:
business:
types:
- name: ORDER
code: "01"
description: "Order sequence"
step: 1000
- name: PAYMENT
code: "02"
description: "Payment sequence"
step: 500The application uses H2 in-memory databases by default. For production, configure your databases:
spring:
datasource:
primary:
url: jdbc:mysql://primary-db:3306/sequences
username: user
password: password
secondary:
url: jdbc:mysql://secondary-db:3306/sequences
username: user
password: passwordThe system consists of several key components:
- SequenceBuffer: Multi-level caching for high-performance sequence generation
- SequenceManager: Database operations with automatic failover
- SequenceGeneratorService: Main business logic
- REST Controllers: HTTP API endpoints
Access the H2 console at: http://localhost:8080/sequence-gen/h2-console
Health check endpoint: http://localhost:8080/sequence-gen/actuator/health
Run tests with:
mvn testThis project is licensed under the MIT License.