Database: MongoDB + DynamoDB
The Users Service originally relied on MongoDB, which offered great flexibility and low latency. However, during rapid, unpredictable traffic surges, some workflows would bypass the cache and hit the database directly. This sometimes led to "connection storms" that could overwhelm the cluster and cause brief unavailability.
To solve this, we moved to a federated, or polyglot, persistence model. We analyzed our access patterns and moved our most frequently accessed, key-value (K-V) lookup datasets to DynamoDB. As a stateless database that doesn't require active connections, DynamoDB is purpose-built to handle unpredictable traffic spikes with consistent performance.
One challenge with DynamoDB is its lack of native unique constraints. We solved this by developing a framework that uses an auxiliary table and multi-item transactions to enforce atomicity when unique constraints are required on one or more columns.
This federated setup, using both MongoDB and DynamoDB, allows us to use the right tool for the right job, managing diverse workloads while maintaining flexibility.
Fig 2: Database topology