Intro to Microservices

Intro to Microservices

MicroService is an architecture that is building software using a collection of independent services that communicate over API. Make application easier to scale and develop faster and less complicated. Accelerate innovation.

MonolithicMicroServices
All processes are tightly coupled in single serviceloosely coupled in multiple service which runs each application as an individual process.
If there is demand for one service, still we have to scale the entire architecture.Services can scale individual.
Adding new features is complicated during this entire application can go down due to being tightly coupled. Therefore, it risks application availability.Technological Freedom where each service can build in any Tech stack separately.

Components

  • Microservices: breaking large apps into small self-contained services to communicate over lightweight protocol. Independent development of each service in any tech

  • Container: units of software that package all the dependencies and code necessary to run that service.

    Note: the container is not necessary for microservice dev, However, a container can potentially improve dev time and app efficiency.

  • Service Mash: create a dynamic messaging layer to facilitate communication. It abstracts the communication layer, which means developers don’t have to code in intra-process communication when they create an application.

  • Service discovery: due to changing workloads, update & failures, no. of active microservices instances fluctuate. It is difficult to track large numbers of services that reside in a distributed network, Service discovery helps service instances adapt to a changing deployment, and distribute the load between the microservices accordingly. The service discovery component is made up of three parts:

    • a service provider that originates service instances over a network;

    • service registry which acts as database that stores the location of available service instances.

    • Service consumer, which retrieves the location of a service instance from the registry, and then communicates with that instance.

  • API Gateway: used to communicate between microservices and outside clients. The API gateway will handle a large amount of the communication and administrative roles that typically occur within a monolithic application, allowing the microservices to remain lightweight. They can also authenticate, cache and manage requests, as well as monitor messaging and perform load balancing as necessary.

Best Practices

  • The Single Responsibility Principle

    it should solve one context of business

  • Separate Data Store

    It defeats the purpose of having microservices if you are using a monolithic database that all your microservices share. Any change or downtime to that database would then impact all the microservices that use the database. Choose the right database for your microservice needs, customize the infrastructure and storage to the data that it maintains, and let it be exclusive to your microservice. Ideally, any other microservice that needs access to that data would only access it through the APIs that the microservice with write access has exposed

  • asynchronous communication to achieve loos coupling.

  • Proxy your microservice requests through an API Gateway

    • can redirect to new version of API prevent unauthorized access to API

    • Clients calling your microservices will connect to the API Gateway instead of directly calling your service. This way you will avoid making all those additional calls from your microservice and the internal URLs of your service would be hidden, giving you the flexibility to redirect the traffic from the API Gateway

    • This is even more necessary when a third party is accessing your service, as you can throttle the incoming traffic and reject unauthorized requests from the API gateway before they reach your microservice. You can also choose to have a separate API gateway that accepts traffic from external networks.

  • Fail fast by using a circuit breaker to achieve fault tolerance

    this will help to improve your SLAs (service level agreement) with your user. If any microservice is depended on 3rd party system and that system is responding late, so we can use circuit break to response fail fast to our user.

  • Backward Compatibility

  • Dedicated Infrastructure for deploying microservices

  • Proper Documentation & logs monitoring of microservices

    • Proper log aggregation, monitoring, API documentation, secrets management, config management, distributed tracing, etc.
  • Security

Conclusion & finding

From this we conclude that Microservices Help to build collection scalable, decoupled, independent services with data independency. Architecture’s is a distributed design approach intended to overcome the limitations of traditional monolithic architectures. Microservices help to scale applications and organizations while improving cycle times. However, they also come with a couple of challenges that might add additional architectural complexity and operational burden.

Did you find this article valuable?

Support Siddhesh Jungade by becoming a sponsor. Any amount is appreciated!