10+ Things I learned Implementing a Micro-services Architecture for a Startup

Having spent the last couple of weeks implementing a Micro-services architecture with Spring Cloud, here are a few things I learned about micro-services:

1. Micro-services is not just Service Oriented Architecture (SOA). And implementing one is a lot harder than it seems on the surface.

2. The architecture requires a token-based Single Sign-On (SSO) of some sort to handle user signup/login, token generation, and authorization by roles and privileges, etc. How else would you manage federated security for 10 or more absolutely independent services?

3. Standing up an OAuth2 server (or using a 3rd party service like google or okta.com) is your best bet for SSO instead of coming up with your own token-based security implementation. 

4. Your API can easily get messy quickly: The reason is, If you break a monolithic application into 10 or more services with each service on a different server and/or different ports, you’re going to end up with that many endpoints in the least and eventually it will become hard to manage. 

5. To solve the problem in number 4, you will need to implement a reverse proxy service to handle internal routing so as to give your entire system a single entry point. And you cannot use Apache or Nginx for this, you will need to build your own. See the next point for the reason.

6. You will need a service registry where all your micro-services will automatically register themselves (their IP and ports) at their boot time. This registry needs to be available to the reverse proxy server. The reverse proxy server will depend on it to pull the list of available services and be able to route incoming requests accordingly. I’m not aware Apache or Nginx can do this.

7. You need a load balancer to handle internal load within the services’ multiple instances: Since one of the advantages of microservices is the ability to scale up or down each service based on load and other factors, your architecture needs to be able to load-balance internally. Your reverse proxy can be designed to serve this purpose alongside its other job.

8. How do you manage logs coming from all your 10 to 15 micro-services and find errors and bugs? You need a centralized log collection system. Crazy ain’t?

9. What happens if you migrate one or more services from one server to another (an IP or port change). Do you need to update and redeploy other services that are already configured to use the old IP and/or ports? This problem is solved by implementing 2 micro-services: 

 a. A centralized configuration management system and b. A service registry (as described above) where all services can automatically register themselves upon startup. 

10. A centralized configuration management service allows all the services to use a ‘single configuration file’. And a service registry allows services to find each other by name instead of by IP address and port.

11. This is optional, but it’s better to implement a centralized session (cache) management system as well. This will allow services access to objects in the cache saved by other services. Of course, a file-based session or cache cannot work. You will have to use Redis, Memcached or a database. 

By the time you’re done with this architecture, you would have built 5 to 6 micro-services just to manage your system. (You will still need to build the business-related micro-services). Below are the likely infrastructure services:

 A. Configuration service.

 B. Service registry.

 C. Proxy & load balancing service.

 D. OAuth2 Authentication service.

 E. Metrics and Log service. 

 F. Session management service.

[Some of these services can be combined together, I only listed them separately for readability. And again, there is no harm if they’re implemented separately.]

12. Building all these (micro-) services is one part of the job, testing, tracing errors and bugs, deployment, and maintaining them is another. And these other parts are not in any way insignificant. It is obvious you will need some form of CI/CD and DevOps system to make these latter jobs easier.

These are the few things i can remember for now. Please leave a question or suggestion for me to make this architecture better. Thanks for reading.

#microservices #devops #springcloud #java #oauth2 #sso #apache #nginx #cicd #tmnuggets

Similar posts