Selecting a Database for High-Volume Activity Tracking
System DesignModel answerLast updated
Evaluate NoSQL versus relational storage for a log ingestion system with extreme write throughput and petabyte-scale growth.
Context
You're building a backend service that tracks user activity events for a SaaS platform. The system needs to store every action users take and provide quick access to recent history.
Requirements
Your service must support:
- Write throughput: 50,000 events per second at peak load
- Query patterns:
- Retrieve the most recent 50 events for any given user
- Count how many events a user generated within a date range
- Scale: Data volume will reach multiple petabytes within three years
- Reliability: Writes must be durable—no accepted events can be lost
- Performance: Response times should remain predictable as data grows
- Cost: Budget matters, but availability and latency are top priorities
Your Task
You're evaluating two options: a managed NoSQL key-value store (like DynamoDB) versus a managed relational database (like RDS MySQL).
For each option:
- Design the schema — Show how you'd structure the data
- Analyze trade-offs — Discuss scalability, consistency guarantees, and operational complexity for this specific workload
- Make a recommendation — Choose one approach and defend your decision with specific reasoning
Questions to Address
- How would each system handle retrieving the top N records efficiently?
- What happens to write performance under high concurrency in each architecture?
- How does query performance change as tables grow past 100 TB?
- What operational burden does each choice create?
Hints
Hint 1
Start by calculating storage volume from write rate and record size—this drives architectural constraints
Hint 2
Consider whether the query patterns require relational features like joins or transactions across multiple entities
Hint 3
Think about how each system partitions data and what that means for hot spots when one user generates far more events than others
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer: Database Selection for High-Volume Event Logging
This problem tests whether you can match workload characteristics to storage engine strengths. The key insight is recognizing that this is a write-heavy, key-scoped workload that doesn't need relational features.
Step 1: Quantify the Requirements
Always start by converting vague requirements into concrete numbers:
Storage math:
- 50,000 writes/sec × 1 KB average = 50 MB/sec sustained
- 50 MB/sec × 86,400 sec/day ≈ 4.3 TB/day
- 4.3 TB/day × 1,095 days ≈ 4.7 PB over three years ✓
Access pattern analysis:
- Both queries are scoped to a single user—no cross-user aggregations
- No joins needed with other tables
- No multi-record transactions required
- Writes are append-only (no updates to historical records)
Clarify "strong consistency": The requirement states writes must never be lost. This is about durability, not read-after-write consistency. A committed write must survive failures.
Step 2: Data Modeling
NoSQL Key-Value Approach (DynamoDB-style)
Partition Key: USER#{tenantId}#{userId}
Sort Key: {timestamp_iso8601}#{eventId}
Attributes:
- event_type
- resource_id
- metadata (small JSON blob)
- ttl (for automatic expiration)
Why this works:
- Partition key groups all events for a user together
- Sort key enables range queries and natural ordering
- "Last 50 events" becomes a reverse range query on one partition:
Query(PK=user, ScanIndexForward=false, Limit=50) - Single-partition queries have consistent single-digit millisecond latency regardless of total table size
Count queries: Naive counting still scans and charges for every item. For frequent counts, maintain a separate aggregation table:
PK: USER#{id}
SK: DAY#{2025-01-15}
counter: atomic increment on each write
Then sum across date buckets for range counts.
Relational Approach (MySQL/InnoDB)
CREATE TABLE events (
user_id BIGINT NOT NULL,
timestamp DATETIME(6) NOT NULL,
event_id BINARY(16) NOT NULL,
event_type SMALLINT,
metadata JSON,
PRIMARY KEY (user_id, timestamp, event_id)
) PARTITION BY RANGE (TO_DAYS(timestamp)) (
-- time-based partitions for archival
);
Why this structure:
- Composite primary key clusters rows by user, then time
- InnoDB stores rows in PK order, making range scans efficient
- "Top 50" is
WHERE user_id = ? ORDER BY timestamp DESC LIMIT 50using the index
The scaling problem: A single MySQL instance caps at 64 TB. Reaching petabytes requires application-level sharding by user_id into 50-100+ independent databases. This means building shard routing logic, handling cross-shard operations, and managing schema changes across the fleet.
Step 3: Trade-off Analysis
Horizontal Scalability
NoSQL: Scales transparently by partitioning data across nodes. Each partition handles ~1,000 writes/sec. The system automatically splits hot partitions as load increases. 50k writes/sec is routine.
Risk: Individual hot keys. If one user generates >1,000 writes/sec, that partition throttles. Mitigation: shard heavy users across multiple partition keys (USER#id#0, USER#id#1, etc.).
MySQL: Write scalability requires manual sharding. Each shard is a single-writer system. Real bottlenecks emerge at scale:
- B-tree depth increases with table size, reducing cache effectiveness
- Buffer pool misses cause random I/O on large indexes
- Replication lag grows under sustained write load
- Adding shards requires application changes and data migration
At 100+ TB, backups take hours, schema changes require careful orchestration, and resharding becomes a multi-week project.
Write Durability & Consistency
NoSQL: Acknowledged writes are synchronously replicated across three availability zones before returning. This guarantees durability.
- Strongly consistent reads available at 2× cost
- Eventually consistent reads are cheaper but may lag by milliseconds
MySQL: Multi-AZ deployments provide synchronous replication to a standby. Commits are ACID within a single database.
- Read replicas are asynchronous (lag of seconds)
- Strong consistency forces reads to the primary, concentrating load
- Cross-shard consistency requires distributed transaction coordination
Query Performance at Scale
NoSQL: Single-partition queries maintain constant latency regardless of total table size (p99 < 10ms). The partition key isolates each user's data.
MySQL: Index depth grows logarithmically. At 10 TB, performance is acceptable. At 100 TB per shard, buffer pool hit rates decline and query times degrade even with proper indexing.
Operational Overhead
NoSQL: Fully managed—no patching, no failover procedures, no capacity planning for individual nodes.
Cost model: Pay per request and storage. High write volume is expensive. Mitigations:
- TTL to auto-delete data after 90 days
- Archive cold data to object storage (S3/Parquet)
- Use provisioned capacity or reserved pricing for baseline load
MySQL: Lower per-GB cost at moderate scale, but adds:
- Sharding middleware maintenance
- Schema migration across dozens of shards
- Manual failover handling and monitoring
- On-call engineering time (hidden cost)
Step 4: Recommendation
Choose the NoSQL key-value store.
Reasoning:
-
Access patterns align perfectly: Every query targets a single user key. No joins, no transactions, no cross-entity queries. This is exactly what partitioned key-value stores optimize for.
-
Scale is native, not bolted-on: 50k writes/sec and petabytes are standard workloads. The alternative requires building and operating a sharded fleet from day one.
-
Predictable latency requirement: Single-partition query latency stays flat as the table grows to petabytes. In MySQL, degradation is inevitable at that scale.
-
Durability without complexity: Multi-AZ replication is built-in and doesn't require application-level failover logic.
Cost management strategy:
- Keep 90 days of hot data in the primary table with TTL enabled
- Stream expired records to object storage for long-term retention
- Use provisioned capacity with autoscaling for predictable baseline load
- Query historical data via serverless analytics (Athena/BigQuery) when needed
Honest weaknesses to acknowledge:
- Per-request pricing makes high write volume expensive
- Hot users (>1k writes/sec) require write sharding
- Count queries need pre-aggregation to be cost-effective
- No ACID transactions if you later need multi-entity consistency
Common Mistakes to Avoid
- Choosing relational storage because "it's more familiar" without considering the operational burden of sharding
- Assuming "strong consistency" means synchronous replication (it means durability)
- Forgetting to calculate storage volume and growth rate
- Not recognizing that lack of joins eliminates the main advantage of relational databases
- Proposing overly complex designs (like sharding both systems) when the workload doesn't require it
Follow-up Considerations
If asked: "What if you need to join with user profile data?"
Don't move petabytes into a relational DB for joins. Instead:
- Denormalize frequently-accessed profile fields into the event record
- Use cache-aside pattern: fetch profile separately when displaying events
- For analytics, join in the data warehouse layer after archival
If asked: "How do you handle schema evolution?"
NoSQL: Add new attributes without migration—just start writing them. Old records don't need backfilling unless queries require it.
MySQL: Schema changes on 100 TB tables require online DDL tools (gh-ost, pt-online-schema-change) and careful coordination across shards.