skip to Main Content

I have been googling a lot concerning how microservices access a redis data but no luck finding good tutorials. Here is my use case.

A user logs into the authentication microservice A (spring boot) for the first time. After being authenticated the user’s profile data are stored in redis cache by microservice A.

Now there are microservice B (spring boot) and microservice C (NodeJs). These two microservices would like to read the profile of the user from redis.

My question is how can these two services B and C know the key that the authentication microservice A used to store the profile data so that they can use it to access the data?

Should redis keys be written in property file and shared among microservices?

How is this done in real world production environment?

Any pointer to a blog or tutorial will be appreciated

2

Answers


  1. If you need to notify other services, and using Redis to do that, you could use the Redis Pub/Sub functionality. You could use a channel newuser that service B and C subscribes to and let service A publish new user keys to that channel as they are created.

    Read more about Redis Pub/Sub

    Login or Signup to reply.
  2. This is a more general problem so I’m gonna ask a leading question. Hope that’s OK.

    How would you share table and field names if you had a relational database that stored user profile data used by multiple microservices?

    If your answer is, "I dunno, that’s a good question", then this is really a question about sharing data between microservices and nothing specific to Redis.

    If you have an answer to that question then use that answer for Redis. The key names in Redis are analogous to the table and field names in a relational database.

    That said, there’s a school of thought that microservices shouldn’t share internal data. That instead they should pass messages or call each other and each should have their own database. And, that if they don’t, it’s really a distributed monolith. I subscribe to this school of thought and so my advice would be to not architect your software this way.

    That said, other fine folks have other opinions and subscribe to other schools and that’s good. After all, there are no solutions—only trade-offs. If I subscribed to another school, I would just store it all in configuration files or hard-code them. Just like I would for database table names.

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