Modul 13 von 15 · 📖 4 min Lesezeit · ⏱ 30 min gesamt
FI-AE 14 Backend-Architekturen — Monolith vs. Microservices (EN)
Inhaltsverzeichnis (6 Abschnitte)
FI-AE 14 Backend Architectures — Monolith vs. Microservices
In this module, you will explore the fundamental backend architectures of modern software development. You will learn about the advantages and disadvantages of monolithic and microservice-based systems and understand how these architectures affect scalability, maintainability, and development speed. You will gain insights into key concepts such as API gateways, service discovery, and asynchronous communication via queues and events.
Concepts and Background
- Monolithic Architecture
- A single, cohesive application system where all functions are developed in one codebase and deployed as a unit. The components are tightly coupled with each other.
- Microservices Architecture
- An approach where an application is developed as a set of smaller, independent services that communicate through defined interfaces. Each service is independently deployable and scalable.
- API Gateway
- A central entry point for all client requests that forwards requests to the appropriate microservices, performs authentication, and handles load balancing.
- Service Discovery
- A mechanism that enables microservices to dynamically discover the network addresses of other services without them being hardcoded.
- Asynchronous Communication
- A form of communication where the sender does not wait for an immediate response. It typically occurs through message queues (e.g., RabbitMQ, Kafka) or events (e.g., EventBus).
Architecture Diagram
flowchart TB Client[Client Application] --> APIGW[API Gateway] APIGW --> Auth[Authentication] APIGW --> Service1[Microservice 1] APIGW --> Service2[Microservice 2] APIGW --> Service3[Microservice 3] Service1 --> ServiceDiscovery[Service Registry] Service2 --> ServiceDiscovery Service3 --> ServiceDiscovery Service1 --> MessageQueue[Message Queue] Service2 --> MessageQueue Service3 --> MessageQueue MessageQueue --> EventProcessor[Event Processor]
Practical Steps
- Define domain boundaries for your microservices based on business functions. This ensures that each service has a clear responsibility.
- Implement an API gateway with a framework like Spring Cloud Gateway or NGINX to centralize access to your services.
Install the necessary dependencies for your Node.js-based microservice framework.npm install -g @nestjs/core @nestjs/common @nestjs/platform-express- Configure a service registry like Eureka or Consul so your services can find each other.
- Implement a Message Queue with RabbitMQ or Apache Kafka for asynchronous communication between services.
Start a RabbitMQ container for message processing.docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management- Define clear service contracts with OpenAPI/Swagger specifications to standardize communication between frontend and backend.
- Implement circuit breaker patterns in your services to prevent cascading failures when a service is unavailable.
- Set up a logging and monitoring system like ELK Stack (Elasticsearch, Logstash, Kibana) or Prometheus with Grafana to monitor your service performance.
- Implement CI/CD pipelines with tools like Jenkins or GitLab CI to enable automated testing and deployments for your microservices.
Common Pitfalls
Further Resources
- Microservices.io - API Gateway Pattern
- Spring Cloud Gateway Documentation
- RabbitMQ Getting Started Guide
- Martin Fowler - Microservices
- Kubernetes - Working with Objects
Knowledge Check
Four questions for self-assessment. Click on each question to see the correct answer and explanation.
What is a key difference between monolithic and microservices architecture?
- A) Monoliths always use SQL databases, microservices use NoSQL
- B) In a microservices architecture, services are independently deployable and scalable
- C) Monoliths are always slower than microservices
- D) Microservices always require more developers than monoliths
Correct Answer: B. The independence of services is a core characteristic of microservices. A is incorrect because both architectures can use different types of databases. C is incorrect because performance depends on implementation. D is incorrect because team size is not directly dependent on architecture.
What function does an API gateway serve in a microservices architecture?
- A) It centrally stores data for all microservices
- B) It manages permissions for each microservice individually
- C) It is a central entry point for client requests and forwards them
- D) It optimizes database queries for all microservices
Correct Answer: C. The API gateway acts as a single entry point and manages requests. A is incorrect because it doesn't store data. B is incorrect because it centrally manages permissions. D is incorrect because it doesn't optimize database queries.
What is the purpose of service discovery in a microservices architecture?
- A) It monitors system performance and alerts on issues
- B) It enables microservices to dynamically discover addresses of other services
- C) It provides load balancing across all services
- D) It manages the deployment lifecycle of services
Correct Answer: B. Service discovery allows services to find each other without hardcoded addresses. A is incorrect as that's monitoring. C is incorrect as that's load balancing. D is incorrect as that's deployment management.