Database Selection & Design (Part IX)

— Microservices Data Access Patterns —

  • Read and Write schemas can be completely different and can be optimized for read efficiency and write efficiency. By storing a materialized view in the read database, the application can avoid complex joins when querying
  • Read and Write store can scale independently. Also, different database types can be used to for read and write stores. Example: Write can happen to relational and read can happen from a non-relations database type
  • Security can be managed more tightly, as there exists a responsibility separation
  • Each view can be complex with relations and can be rebuilt at the background
  • The consistency of data between them should be closely managed. It is always going to be eventual consistency, due to which there will be a stale data read situation can can come up from this design. This pattern is different from caching by where the data is stored.
  • The design can get more complex quickly, as you combine this with other patterns like Event Sourcing
  • When you want to capture intent, purpose, or reason in the data
  • When it’s vital to minimize or completely avoid the occurrence of conflicting updates to data
  • When you want to record events that occur and be able to replay them to restore the state of a system, roll back changes, or keep a history and audit log
  • When using events is a natural feature of the operation of the application and requires little additional development or implementation effort.
  • When you need to decouple the process of inputting or updating data from the tasks required to apply these actions. This might be to improve UI performance, or to distribute events to other listeners that take action when the events occur
  • When used in conjunction with CQRS, and eventual consistency is acceptable while a read model is updated, or the performance impact of rehydrating entities and data from an event stream is acceptable.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Faisal Mohamed

Engineering Director, People Leader, Offroader, Handyman, Movie Buff, Photographer, Gardener