iluwatar / iluwatar/java-design-patterns
Microservice pattern: Database per service
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 94.7k
- Forks
- 27.4k
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 10
Description
Description:
The Microservices - Database per Service design pattern advocates for each microservice to have its own private database. This design pattern is crucial for achieving loose coupling between microservices, allowing each service to be developed, deployed, and scaled independently. Here are the main elements of this pattern:
- Service Independence: Each microservice has its own database schema and database server. This isolation ensures that services do not interfere with each other’s data.
- Scalability: Individual microservices can be scaled independently according to their specific data access and storage needs.
- Polyglot Persistence: Different microservices can use different types of databases (SQL, NoSQL, etc.) based on their specific requirements.
- Data Consistency: Ensuring eventual consistency through patterns like Saga or event sourcing is crucial since distributed transactions are not feasible.
- Security and Access Control: Each microservice manages its own database security, ensuring data encapsulation and reducing the risk of unauthorized access.
References:
- Microservices Patterns: With examples in Java
- Martin Fowler on Microservice Architecture
- Database per Service Pattern
- Project Contribution Guidelines
Acceptance Criteria:
-
Design and Documentation:
- Clearly define the architecture diagram showing multiple microservices with their own databases.
- Update project documentation to include details on the Database per Service pattern, its benefits, and challenges.
-
Implementation:
- Implement a sample microservices application demonstrating the Database per Service pattern.
- Each microservice should interact with its own separate database.
- Demonstrate polyglot persistence by using at least two different types of databases.
-
Testing:
- Write unit tests to ensure each microservice can independently access and manipulate its data.
- Implement integration tests to validate data consistency across services using eventual consistency mechanisms.
-
Example Scenario:
- Provide an example scenario (e.g., e-commerce application) where multiple services (e.g., Order, Product, User) have their own databases.
- Show how these services interact with each other and maintain data consistency.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Project Contribution Guidelines and review the existing project structure for related design-pattern examples; the issue names no implementation files or tests. Done requires documentation with an architecture diagram, a Java microservices example using separate databases and at least two database types, unit and integration tests, and an e-commerce scenario demonstrating eventual consistency.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- databases, distributed-systems, documentation
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100