Database Technologies
Each microservice manages its own database, following the database-per-service pattern:| Service | Database | Technology | Purpose |
|---|---|---|---|
| Catalog | PostgreSQL | Marten (Document DB) | Product catalog with flexible schema |
| Basket | PostgreSQL + Redis | Marten + Cache | Shopping cart with caching layer |
| Ordering | SQL Server | Entity Framework Core | Complex order management with relationships |
| Discount | SQLite | Entity Framework Core | Lightweight coupon management |
Why Polyglot Persistence?
Different services have different data storage requirements:Document Storage (PostgreSQL + Marten)
- Use Case: Catalog and Basket services
- Benefits: Flexible schema, JSON document storage, ACID transactions
- Perfect For: Product catalogs and shopping carts with varying attributes
Relational Database (SQL Server)
- Use Case: Ordering service
- Benefits: Strong consistency, complex relationships, transactional integrity
- Perfect For: Order management with multiple related entities
Cache Layer (Redis)
- Use Case: Basket service
- Benefits: In-memory performance, distributed caching, session storage
- Perfect For: Frequently accessed shopping cart data
Embedded Database (SQLite)
- Use Case: Discount service
- Benefits: Zero-configuration, serverless, lightweight
- Perfect For: Simple read-heavy workloads like coupon lookups
Database Independence
Each service maintains complete database independence:- Schema Isolation: No shared tables or schemas
- Technology Freedom: Each service chooses its optimal database
- Independent Scaling: Databases scale independently based on load
- Migration Safety: Schema changes don’t affect other services
Connection Management
All connection strings are configured inappsettings.json:
- Stored in Azure Key Vault or similar secret management
- Never committed to source control
- Injected via environment variables or configuration providers
Health Checks
Each service implements database health checks:/health on each service.
Next Steps
PostgreSQL Setup
Configure Marten for document storage
SQL Server Setup
Configure Entity Framework Core
Redis Caching
Implement distributed caching
SQLite Configuration
Set up embedded database
