Getting Started - Microservices Architecture

Course link - https://courses.dometrain.com/courses/take/getting-started-microservices-architecture
Author - James


Monoliths

SOA

SOA vs Microservice
Pasted image 20250210235227.png

API mandate by Bezos

Microservice

Microservices is an architectural style where an application is built as a collection of small, independent services, each focused on a single business capability and communicating via lightweight protocols (such as REST, gRPC, or message queues).

Microservices break applications into small, independent services that communicate via APIs, unlike monoliths that are tightly coupled.

If asked about microservices, include these key aspects:

  1. Decentralization: Each service has its own database and operates independently.

  2. Autonomy: Services can be developed, deployed, and scaled independently.

  3. Communication: Services interact via RESTful APIs, gRPC, or message brokers like Kafka, RabbitMQ.

  4. Resilience: Failure of one service does not bring down the entire system.

  5. Scalability: Each microservice can be scaled individually based on demand.

  6. Technology Agnostic: Each service can be built using different technologies (polyglot architecture).

  7. CI/CD & DevOps Friendly: Works well with containerization (Docker, Kubernetes) and automated deployments.

  8. How do microservices communicate?

    • Answer:
      • Synchronous: REST APIs, gRPC
      • Asynchronous: Message brokers (Kafka, RabbitMQ)
  9. How do you handle data in microservices?

    • Answer:
      • Database per Service – Each service has its own DB.
      • Event Sourcing – Track state changes as events.
      • CQRS (Command Query Responsibility Segregation) – Separate read and write models.
  10. How do you ensure security in microservices?

    • Answer:
      • Authentication: OAuth2, JWT, API Gateway
      • Authorization: Role-based access control (RBAC)
      • Service-to-Service Security: mTLS (Mutual TLS)
  11. What are some challenges in microservices?

    • Answer:
      • Service Discovery: Need tools like Consul, Eureka.
      • Data Consistency: Hard to maintain ACID transactions.
      • Monitoring: Requires logging & tracing (ELK, Prometheus).
      • Distributed Tracing: OpenTelemetry, Jaeger.
  12. What tools are commonly used in microservices?

    • Answer:
      • API Gateway: Nginx, Kong, Apigee
      • Service Discovery: Consul, Netflix Eureka
      • Container Orchestration: Kubernetes, Docker
      • Logging & Monitoring: ELK Stack, Prometheus, Grafana

Microservices are great when done correctly. However, there are bad of microservices:

Eight fallacies of Distributed system:

https://en.wikipedia.org/wiki/Fallacies_of_distributed_computing

{BE7C7CC6-88B5-467B-977E-3A6E9CC7C200}.png

Pasted image 20250211002329.png

Why DDD and Event storming?


Service Boundary

Boundaries should be aligned with a business domain.

Pasted image 20250211235722.png

Coupling and cohesion

Target "loose coupling, high cohesion" for stable system.

Cohesion - Things that change together - live together.
Cohesion is much simpler to get right than coupling.
Coupling is the silent killer in your application
- High coupling leads to 'distributed monolith'

{15333EA5-BD38-4C15-987E-FE1FB00BEBD9}.png

Pasted image 20250212000726.png

Pasted image 20250212001144.png


Sharing data

Pasted image 20250212001450.png