DEV Community

Cover image for Notes on Microservices — Part 1
Amit Chaurasia
Amit Chaurasia

Posted on

Notes on Microservices — Part 1

Microservice architecture is a variant of the service-oriented architecture structural style.

  1. Microservices Design Patterns:

    1. Database per Microservice
    2. Event Sourcing
    3. CQRS
    4. Sagas
    5. BFF(Backend for Frontend)
    6. API Gateway
    7. Strangler
    8. Circuit Breaker - prevent cascading failures by temporarily preventing further calls to a service that is failing frequently.
    9. Externalized Configuration
    10. Consumer-Driven Contract Tracing
    11. Side car pattern
    12. Bulkhead pattern
    13. Outbox pattern
  2. Smart Endpoints and Dumb Pipes: Microservices aim to be as decoupled and as cohesive as possible. Like Unix pipes (HTTP request-response and RESTish protocols), or messaging over lighweight message bus (RabbitMQ). Issue: The biggest issue in changing a monolith into microservices lies in changing the communication pattern.

  3. Two ways to achieve the sagas:

    1. Choreography [design pattern where each component or service interacts with other components or services through an exchange of messages.]
    2. Orchestration [design pattern where a central controller manages a series of complex tasks or workflows.]
  4. API Gateway can serve below functions:

    Reverse proxy

    Forwarding client services to servers

    Authentication

    SSL termination

    Caching

  5. Strangler design pattern: Is a migration design pattern to incrementally transform your monolithic application to microservices by replacing old functionality with a new service. Once the new component is ready, the old component is strangled and a new one is put to use.

  6. Consumer-Driven Contract Tracing: When one team knows the “domain language” of the bounded context but not the individual properties of each aggregate and event payload, the consumer driven contracts approach may be effective.

  7. What is the difference between Cohesion and Coupling?

    Coupling is the relationship between two or more modules while cohesion is the relationship between two or more parts within a module.

  8. SAGA pattern solves the problem of distributed transaction failures.

  9. Ingress is a mechanism whereby a service can be exposed to clients outside the cluster.

Advantages that Microservices Architecture provides:

  1. Shortens the release cycle with continuous delivery.
  2. Applications are built as a collection of small functional modules. These modules are deployed independently.
  3. They are scalable and can communicate with each other over standard protocols.
  4. Allows for flexibility in terms of technology choices for writing services.
  5. Allows for more fault-tolerant systems, as a failure in one service can be isolated and handled without affecting the entire system.
  6. Modularity.

Challenges with implementing Microservices Architecture:

  1. Operational complexity increases.
  2. Communication overhead - Inter-service communication.
  3. Accurate pre-planning is required.
  4. Architectural Complexity increases.
  5. Testing and Debugging.
  6. Monitoring and Traceability.
  7. Implementing security can be challenging.
  8. Data aggregation. In order to have a full view of a working system, it is required to extract data sets from the microservices repositories and aggregate them into a single schema. For example, to be able to create operational reports that are not possible using a single microservice repository.

Key characteristics of a well-designed Microservice:

  1. Clear, single responsibilities.
  2. Loosely coupled.
  3. Have high cohesion.
  4. Communicate via APIs.
  5. Have bounded context.
  6. Are independently deployable, testable and scalable.

Considerations when designing microservices:

  1. Follow the domain driven design approach.
  2. Carefully define bounded context.
  3. Message format design.
  4. Refactoring a distributed architecture is more difficult as interface changes need to be coordinated.
  5. Be aware of the anti-patterns to microservices and avoid them as much as possible.
  6. Handling service security and service encryption.
  7. Implementing service monitoring and service logging, service tracing and service debugging.
  8. Organization of your microservices source code - mono repo or you create multiple repo for dthe different microservices.
  9. CI/CD implementation.
  10. Automated testing in CI/CD pipelines.
  11. Handling operations that spans multiple services, which collaboration patterns should you use and how.

Measuring success of your microservices architecture:

  1. Lead time - time from commit to deploy
  2. Deployment frequency - number of deploys per day per developer
  3. Failure rate - how often deployments fail
  4. Recovery time - time to recover from an outage

Word Cloud:
service mesh, kubernetes, sidecar proxy, HATEOAS, docker, containers, service discovery, data plane, control plane, ingress, Blue green deployment, Service Orchestration, service choreography

References/Attributions:
Wikipedia
Other sources on internet
https://unsplash.com/photos/ZfVyuV8l7WU
https://microservices.io/post/antipatterns/2019/01/14/antipattern-microservices-are-the-goal.html

Top comments (0)