Microservices & Event-Driven Architecture (EDA) Mastery

Database Per Service: Managing data consistency

1 Views Updated 5/4/2026

Data Independence

If your microservices share a database, you have Distributed Monolith. Real microservices own their schema and their storage mechanism.

1. Loose Coupling

When each service has its own DB, Team A can migrate their SQL schema without Team B even knowing. One service can use **Postgres** for complex queries, while another uses **MongoDB** for high-write logging. This 'Polyglot Persistence' allows you to pick the right tool for each specific job.

2. The Challenge: Distributed Data

You lose **ACID Transactions** across the whole system. You can't wrap a 'Place Order' and 'Charge Card' in a single SQL transaction if they are in different databases. We solve this using the **Saga Pattern** or **Eventual Consistency**—trading immediate consistency for high availability.

4. Interview Mastery

Q: "Should every microservice have its own PHYSICAL database server?"

Architect Answer: "Not necessarily. For an MVP, you can have 1 physical SQL server with separate **Logical Databases** (schemas) for each service. The key is that Service A **NEVER** queries Service B's tables directly. Once you scale, you can easily move those logical databases to separate physical hardware without changing a single line of code in the services."

Microservices & Event-Driven Architecture (EDA) Mastery
1. Foundations of Microservices
The Monolith to Microservices transition: When and why? Domain Driven Design (DDD): Bounded Contexts and Aggregates Database Per Service: Managing data consistency Service Discovery and Health Checks in .NET
2. Communication Patterns
Synchronous Communication: HTTP/gRPC and Service Mesh Asynchronous Communication: Message Brokers (RabbitMQ/Kafka) API Gateways: YARP (Yet Another Reverse Proxy) vs Ocelot Protobuf and Shared Contracts: Managing breaking changes
3. Event-Driven Architecture (EDA)
Introduction to EDA: Producers, Consumers, and Topics The Publisher/Subscriber Pattern in .NET Event Sourcing: Capturing every state change CQRS (Command Query Responsibility Segregation) with MediatR
4. Distributed Transactions & Resiliency
The Saga Pattern: Orchestration vs Choreography The Outbox Pattern: Ensuring reliable message delivery Idempotency: Preventing duplicate message processing Distributed Locking with Redis (Redlock)
5. Observability & Monitoring
Distributed Tracing with OpenTelemetry Centralized Logging: ELK Stack (Elasticsearch, Logstash, Kibana) Metrics and Dashboards: Prometheus and Grafana Correlation IDs: Tracking requests across services
6. Security & Identity
Centralized Authentication: IdentityServer4 & Duende Identity OAuth2 and OIDC Flow for Microservices API Key Management and Rate Limiting Mutual TLS (mTLS) for Internal Service-to-Service Security
7. Infrastructure & Deployment
Containerization: Production-grade Dockerfiles Kubernetes for .NET: Pods, Services, and Ingress Helm Charts: Managing complex deployments Blue-Green and Canary Deployments in K8s
8. FAANG Microservices Case Studies
Case Study: Designing a Global Notification Engine (Reliability at Scale) Case Study: Building a High-Performance Logging Pipeline (PB/Day)