ADVANCED⚙ Go Backend5-6hMilan
Payment Settlement Service (DDD)
Model a payment settlement service using Domain-Driven Design in Go. Handle the full lifecycle: authorization → clearing → settlement, with proper aggregate roots, domain events, and repository patterns. This directly mirrors Gnosis Pay's card payment backend.
Tech Stack
GoDDD patternsPostgreSQLDomain eventsCQRS (read/write separation)
What You'll Learn
- →DDD tactical patterns: Aggregates, Value Objects, Domain Events
- →Payment lifecycle: auth → capture → clear → settle
- →Event sourcing basics for audit trails
- →Repository pattern with PostgreSQL
- →Idempotency keys for payment processing
Milestones (0/5)
M2Repository & persistence
M3Settlement batch processor
M4CQRS read model & API
M5Testing & error scenarios
Architecture Hints
Architecture (DDD Layers)
Maps to Gnosis Pay:
- Payment aggregate = Visa card transaction lifecycle
- Idempotency = Visa network may retry authorizations
- Settlement batching = daily Visa settlement process
- Domain events = audit trail for compliance
┌─────────────────────────────────────┐
│ API Layer (HTTP) │
│ POST /payments/authorize │
│ POST /payments/:id/capture │
│ GET /payments (read model) │
└────────────────┬────────────────────┘
│
┌────────────────▼────────────────────┐
│ Application Services │
│ PaymentService.Authorize() │
│ SettlementService.RunBatch() │
│ (orchestration, no business logic) │
└────────────────┬────────────────────┘
│
┌────────────────▼────────────────────┐
│ Domain Layer │
│ Payment (Aggregate Root) │
│ Money, CardHolder (Value Objects) │
│ PaymentAuthorized (Domain Event) │
│ PaymentRepository (interface) │
└────────────────┬────────────────────┘
│
┌────────────────▼────────────────────┐
│ Infrastructure Layer │
│ PostgresPaymentRepository │
│ EventPublisher (Kafka/channel) │
│ Read Model Projector │
└─────────────────────────────────────┘Interview Talking Points
- ▸Walk through the payment lifecycle and how each state maps to Visa's authorization/clearing/settlement flow
- ▸Explain why DDD is appropriate for payment processing — complex business rules, invariant enforcement
- ▸Discuss idempotency key pattern and why it's critical for financial transactions
- ▸Talk about CQRS trade-offs — eventual consistency in read models vs strong consistency in writes
- ▸Explain how domain events enable audit trails required for financial compliance