Skip to main content
AspNetRun Microservices uses a polyglot persistence approach, selecting the most appropriate database technology for each service’s specific needs.

Database Technologies

Each microservice manages its own database, following the database-per-service pattern:
ServiceDatabaseTechnologyPurpose
CatalogPostgreSQLMarten (Document DB)Product catalog with flexible schema
BasketPostgreSQL + RedisMarten + CacheShopping cart with caching layer
OrderingSQL ServerEntity Framework CoreComplex order management with relationships
DiscountSQLiteEntity Framework CoreLightweight 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 in appsettings.json:
{
  "ConnectionStrings": {
    "Database": "connection-string-here"
  }
}
For production deployments, connection strings should be:
  • 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:
builder.Services.AddHealthChecks()
    .AddNpgSql(connectionString)     // PostgreSQL
    .AddSqlServer(connectionString)   // SQL Server
    .AddRedis(connectionString);      // Redis
Health endpoints are available at /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

Build docs developers (and LLMs) love