It is the characteristic of microservice architecture to take the business service with single goal to solve single problem as microservice .Niket stay Beehively Work , This is a popular online platform for parent communication and credit and attendance management ,Beehively It's a Ruby application , these years , It has grown into a website with many features , Including transcripts, reports, notifications, reminders, etc , stay 2013 year , The development team decided to start with Ruby Write the Stonehenge architecture switch to Go Language and Ruby Hybrid microservice Architecture .
Ruby It's a complex language ,Ruby Beautiful on the surface , But there's a complex heart , Just like our bodies .
When they first started ,Ruby It's useful to be powerful and complex , But over time , The complexity of language permeates into Beehively In the code base , When the project is small Ruby It's a good language . They decided to switch to a new language and architecture to constrain the complexity of the code base .
This conversation is about ： Why do they switch to microservice architecture ？ Why? Go It's a good choice for microservice architecture ？
Ruby The pain of
There are three main reasons for them to move away Ruby It's a monolithic structure .
1. Memory consumption versus speed ; Apply a lot of data caching in memory to improve performance , however Ruby Distribution and GC Recycling takes a lot of time , Finally, it offsets the huge performance improvement brought by cache , They use UX workaround Hiding the slow , And bought bigger boxes , Although it works normally for a while , And finally it reached the tipping point .
2. Concurrent ： stay Ruby Concurrency is achieved by using multiple processes , Applications need a lot of worker, Each runs in its own process , This increases their memory consumption .
3. Compatibility test ： In their experience ,Ruby It's very fast development , It's a way of destroying a lot of things , Important library packages will be discarded , The frame will merge into the frame , When your product is young , So your product is still less dependent on , You can be liberated and the product is beautiful , But sometimes you need more stability ,Go Community culture is more conducive to stability , And avoid disruptive changes .
In order to achieve a better user experience and take advantage of more modern technology , After months of work , They rewrote the code , But the new system is still a little less functional than their old system , Even though the new code is better , But it can't be handed over to their customers , Because it's not functional enough , therefore , They are in an awkward dilemma , The second new system is good , But it can't completely replace the first system in function .
Migration to microservices is the solution to this problem .
Moving to a microservice doesn't mean rewriting the entire application , They can propose components as separate applications .
Three core components PDF generator , alert System , and Report card calculation grade calculator Break down into three separate microservices .
See the original text for details ....
They use Nginx Route requests to these microservices or major Ruby application ,Redis It's an effective tool to combine main application and micro service ,Go The micro service of will Ruby The application is seen as a API Client or upstream agent . You need a simple Authorization , Microservices and main applications can be expanded independently .
Go In terms of deployment, it's simple , Just build rsync And through the upstart restart .
stay 2013 After switching ,Beehively Found a clean and beautiful new architecture , Here is their experience ：
1. Go Language is a process of writing Web Simple service, great language , It's especially suitable for microservices , This not only refers to GO The language itself , And some of the tools and community culture around it .
2. Instead of rewriting the entire application from scratch , You can use some components specifically Go Micro services replace , So as to reduce the workload , But it brings more benefits , up to now , They haven't reduced any of the features that customers rely on .
3. Even if the new architecture needs to deploy multiple services ,Go Make deployment simple , This is critical from a system management perspective .
For teams whose development slows down due to complexity , They highly recommend Go Language rewriting .