System Design: Strongly Consistent Ledger and External Service Integration
Context and Goal
You are asked to design two components in a production-grade environment:
-
A financial ledger with strong consistency and high scalability.
-
An integration of an external "Bikemap" routing library/service into a larger application.
Assume:
-
Money movement requires correctness over availability. Writes must be strongly consistent. Reads can be tuned for performance while preserving correctness.
-
Bikemap is a third-party routing API used to fetch bicycle routes/metadata; think of it as a network API with SLAs, rate limits, and versioned contracts.
Part A — Ledger System Requirements
Design a ledger that provides:
-
Consistency and correctness
-
Double-entry accounting (every transaction balances to zero).
-
Immutability and auditability (no destructive updates; reversible corrections).
-
Idempotent writes; exactly-once effects externally.
-
Strong write consistency (linearizable writes, serializable transactions).
-
Scalability and performance
-
High write throughput; horizontal scaling.
-
Efficient balance reads (point-in-time and as-of time).
-
Reliability and security
-
Multi-AZ durability, backups, disaster recovery.
-
Encryption at rest/in transit; access controls.
-
Interfaces and operations
-
Well-defined APIs (create account, transfer, hold/release, reverse, query balance, list transactions).
-
Observability, schema evolution, and operational playbooks.
Describe: data model, write/read paths, sharding strategy, multi-account transaction handling, audit guarantees, idempotency, and failure handling.
Part B — Integrate an External Bikemap Service
Explain how you would integrate an external Bikemap library/service into a larger application, covering:
-
API design
-
Internal domain API that remains stable even if the provider changes.
-
Versioning, contracts, and auth/secrets management.
-
Data flow
-
Request flow, caching, rate limiting, retries, timeouts, and circuit breakers.
-
Sync vs async flows and background jobs.
-
Error handling and resilience
-
Error taxonomy, fallback strategies, and observability.
-
Deployment considerations
-
Environment promotion (dev/staging/prod), canaries, feature flags, infrastructure, and testing strategies.