skip to Main Content

Say I have a service that manages warehouses(that is not very frequently updated). I have a sales service that requires the list of stores( to search through and use as necessary). If I get the list of stores from the store service and save it( lets say in redis) inside my sales service but ensure that redis is updated if the list of stores changes. Would it violate the single responsibility principle of Microservice architecture?

3

Answers


  1. No it does not, actually it is quite common approach in microservice architecture when service stores a copy of related data from another services and uses some mechanism to sync it (usually using some async communications via message broker).

    Storing the copy of data does not transfer ownership of that data from service which manages it.

    Login or Signup to reply.
  2. It is common and you have a microservice pattern (CQRS).

    If you need some information from other services / microservices to join with your data, then you need to store that information.

    Login or Signup to reply.
  3. Whenever you are making design decision whether always issue requests against the downstream system or use a local copy then you are basically making trade-off analysis between performance and data freshness.

    • If you always issue RPC calls then you prefer data freshness over performance
      • The frequency of how often do you need to issue RPC calls has direct impact on performance
    • If you utilize caching to gain performance then there is a chance to use stale data (depending on your business it might be okay or unacceptable)
      • Cache invalidation is a pretty tough problem domain so, it can cause headache

    Caching one microservice’s data does not violate data ownership because caching just reads the data, it does not delete or update existing ones. It is similar to have a single leader (master) – multiple followers setup or a read-write lock. Until there is only one place where data can be created, modified or deleted then data ownership is implemented in a right way.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search