Reputation: 11
I have a realtime(latency of 10ms) monolithic service that does multiple things in a single execution. I am facing a lot of problems because of monolithic architecture specially scaling team and maintaining complex code base. I have identified 3 different functional services and planning to split the monolithic service into 3 different services. But all of these services depend on the same data.
Since currently there is only 1 execution of code we only need to hit DB(currently its Redis) once in the call. After splitting there are 2 options
Please share your experience on which way is better or if there is any better solution to this problem.
Upvotes: 0
Views: 745
Reputation: 138
I don't think there's a magic bullet, but I'd recommend a few things to think about when cutting up a monolith.
First, beware of "Monolith split into microservices". Monolith and microservices are two different beasts, each needs it's own approach. Microservices can help you scale the team and cut down maintenance costs. But let's also remember that monolith architecture enabled you not to think about latency between modules or the size of objects you send between them. Changes in architecture needs to be accompanied by changes in used patterns, e.g.,:
A different trap is "splitting logically". Business logic often provides a nice and easy-to-understand way to split your code. But that is not always the best latency-wise. Thus I suggest to think carefully about your data flows, before deciding on the exact cut lines. What are your minimal requirements for your data flows? Try drawing some kind of dependency graph and minimize it first before doing the actual split. Personally, I'd prefer an iterative approach by first spending some months (depending on project size) preparing the code - removing dependencies and reorganizing the code in would-be microservices. Review the split every month or so. If the split still looks good in 3-4 moths, they you probably got it right (enough).
There's probably a few more things to think about, but I assume you got my point - make sure you have the right architecture and appropriate patterns. But you may still end up with the initial question (pass data between services vs. fetch multiple times). If so, I still don't think there's a generic answer as there's too many variables:
All that being said, it seems simpler design to fetch data directly from source in each service - from DB or calling a service to provide the data. Simpler designs may pay back with the lower maintenance costs :)
Upvotes: 2