Data Management - pratchaya-maneechot/service-exchange GitHub Wiki

Data Management

Database Strategy

Database per Service Pattern

Each microservice owns its data and exposes it only through its API.

Service Database Type Justification
User & Identity PostgreSQL ACID compliance, relational data
Task Management PostgreSQL Complex queries, transactions
Bidding & Negotiation PostgreSQL Transactional integrity
Payment PostgreSQL Financial data, ACID critical
Review & Rating MongoDB Flexible schema, read-heavy
Notification MongoDB Varied message structures
Location & Mapping PostGIS Geospatial queries
Support & Dispute MongoDB Flexible ticket structures

Caching Strategy

Multi-level Caching:

  1. CDN Level: Static assets, API responses
  2. API Gateway Level: Response caching
  3. Service Level: Redis for frequently accessed data
  4. Database Level: Query result caching

Cache Patterns:

  • Cache-Aside: Application manages cache
  • Write-Through: Cache updated on write
  • Write-Behind: Asynchronous cache updates

Data Consistency Patterns

Strong Consistency (ACID)

  • Payment transactions
  • User authentication
  • Critical business operations

Eventual Consistency

  • Notification delivery
  • Search index updates
  • Analytics data
  • Cross-service data synchronization

Saga Pattern Implementation

Task Assignment Saga:

1. Create Escrow (Payment Service)
2. Assign Task (Task Service)
3. Notify Parties (Notification Service)

Compensation Actions:
- Release Escrow if assignment fails
- Revert task status if notification fails
⚠️ **GitHub.com Fallback** ⚠️