I'm starting a personal project to learn about what's the best way to implement microservices. It might be onverengineered but it's more like a learning process. It's probably irrelevant but I'm using .Net Core
How I'm think of designing the solutions is as follow:
- Using CQRS pattern so that can easily separate Query and Commands. At the moment, I have 2 end points for that
- I have a "manual" API gateway which will act as a proxy for the different microservices I would need
- Use NServiceBus to communicate between the microservices
Questions:
- I'm thinking of using Redis to cache the Queries. For example, caching the user details. However, as it's a cache, I don't think it should be the source of truth which means I will update another datastore at the same time. From my understanding of the best practices, 1 microservice should only deal with 1 datastore only. So I will create a endpoint dealing with the cache data only which make sense for me.
What would be the best way to handle and add/update command? Update the cache and fire an event to update the main data store? Or update the data store and fire event to update the cache. My feeling is that I should update the main datastore first before the cache (because I wasn't planning to expose and endpoint to update the cache, it should for readonly purpose only) but that would lead to some potential inconsistency. While I get that, in the microservices world, the data is "eventually consistent", doesn't that mean for a simple operation like an update, the user might not directly have his personal data updated even if he submits his changes? - I can see that people are more and more advocates event sourcing. If (at the moment), I don't really need an auditing or even a way to replay the events, do I need it ? I have a feeling I can do it all using an message bus / sagas which, I think, is much more performant that using an event store. Am I correct?