iluwatar / java-design-patterns

Design patterns implemented in Java
https://java-design-patterns.com
Other
90.06k stars 26.61k forks source link

Microservice pattern: Database per service #2666

Open iluwatar opened 1 year ago

iluwatar commented 1 year ago

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:

  1. 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.
  2. Scalability: Individual microservices can be scaled independently according to their specific data access and storage needs.
  3. Polyglot Persistence: Different microservices can use different types of databases (SQL, NoSQL, etc.) based on their specific requirements.
  4. Data Consistency: Ensuring eventual consistency through patterns like Saga or event sourcing is crucial since distributed transactions are not feasible.
  5. Security and Access Control: Each microservice manages its own database security, ensuring data encapsulation and reducing the risk of unauthorized access.

References:

Acceptance Criteria:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
Dinozavvvr commented 7 months ago

Hi @iluwatar, I would be glad to implement it! please assign it to me

stale[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. The issue will be unassigned if no further activity occurs. Thank you for your contributions.

Deepinder04 commented 1 month ago

Hi @iluwatar, I have experience working with multiple micro-services each with separate databases, I would like to implement this, could you please assign it to me?