How to maintain data consistency and implement queries?

59 views
Skip to first unread message

nadeem qasmi

unread,
Feb 26, 2020, 1:10:00 AM2/26/20
to microservices
We have built a complete system by using a microservices architecture. We used a private database per service. Is it a good approach,
or which one is the best?


  • Database per Service - each service has its own private database
  • Shared database - services share a database
  • Saga - use sagas, which a sequences of local transactions, to maintain data consistency across services
  • API Composition - implement queries by invoking the services that own the data and performing an in-memory join
  • CQRS - implement queries by maintaining one or more materialized views that can be efficiently queried
  • Domain event - publish an event whenever data changes
  • Event sourcing - persist aggregates as a sequence of events

Ci-Ci Thomson

unread,
Mar 4, 2020, 7:08:47 PM3/4/20
to microservices
There is no one perfect way.  It depends on your use case.

Peter

unread,
Mar 6, 2020, 10:11:19 AM3/6/20
to microservices
Hi nadeem,

As Ci-Ci wrote there is no perfect way.

In general a microservice is responsible for a business capability or concept. E.g. customers, orders, products, etc. It makes sense to use the database per service pattern. This allows the service to keep full control over its data and prevents the possible temptation of not only reading, but also writing data maintained via other services.

Other services can still access the data, but instead of directly accessing the database a direct protocol (e.g. api via http, grpc, etc.) could also support the possibility to access data from other microservices.

Of course this would still mean the services depend on each other. To handle this you could also choose to keep local abstractions of data maintained by other services. E.g. the order service keeps copies of product descriptions and prices maintained by the product service. Subscribing to events from the product service the local data can be kept up-to-date.


HTH. Cheers,

Peter




Op woensdag 26 februari 2020 07:10:00 UTC+1 schreef nadeem qasmi:
Reply all
Reply to author
Forward
0 new messages