Microservice - MacKittipat/note-developer GitHub Wiki

Microservice

  • Collection of loosely coupled, autonomous services and communicate via network call.
  • Independently releasable services that are modeled around a business domain.
  • Loose-coupling : (Degree to which the different modules/classes depend on each other)
    • Each services can be developed and deployed independently of one another.
  • High-cohesion : (Degree to which the elements of a module/class belong together)
    • Each service do only one thing.

Key concepts

  • Independent Deployable
  • Modeled around a business domain
  • Avoid the used of shared database

Benefits

  • Each service can be build with different technology.
  • If one of service die, it does not have impact to other service. (Tolerance to partial failure)
  • Scale only high traffic service.
  • Deploy each service is independent from other service.

Pain points

  • Developer experience. If there are 20 microservices, can developer run all services on their machine ?
  • Technology overloaded. If each microservice use difference technology
  • Making report is difficult because data is not in the same location
  • Latency
  • Data consistency
  • Monitoring and debugging
  • Cost

Synchronous vs Asynchronous

Synchronous

  • Request/Response or Orchestration.
  • Request/Response can be Asynchronous. Client send asynchronous request and wait for callback.
  • Request to server is blocked until the operation complete.
  • Example, RPC, REST

Asynchronous

  • Event-base or Choreography
  • Client emit event and other services can subscribe to event.
  • Example, Message broker

Tools

Configuration Server

  • Spring Cloud Config

Service Discovery

Example :

It is :

  • It is database of available service instances.
  • Once service instance is start, It will register with Service discovery.
  • Once service instance is down, it will be remove from Service discovery.

Why need it :

  • In cloud environment, Service instance have dynamic IP address. Service consumer need to find location of service by Service discovery.
  • Offer ability to quickly scale number of service instance. Service consumer are abstracted away from physical location of service.
  • It help increase application resiliency. When a service instance becomes unhealthy or unavailable, most service discovery will remove that instance from its internal list of available services.

Circuit Breaker

API Gateway

  • Zuul
  • Kong

It is :

  • Filter, Router for all services.
  • Acts as an intermediary between the service client and a service being invoked.

Why need it :

  • Implement security, logging, metric in API Gateway only instead of in all services.

Ref