Design a System to Fetch Events Within a Time Range
Requirements: Design a system that ingests events occurring at regular intervals and supports efficiently fetching all events that fall within a given input time range.
Design considerations: High write throughput (events arriving continuously), efficient range queries by timestamp, and scalability as the volume of events grows.
Approach: Store events indexed by timestamp using a data structure/index that supports efficient range queries - e.g., a B-tree/B+tree index on timestamp in a relational store, or a time-series-oriented store partitioned by time buckets (e.g., per-hour/per-day shards). For very high write volume, buffer writes and flush in batches to time-partitioned storage; range queries then only need to scan the relevant time partitions. Discuss trade-offs between a relational DB with a timestamp index vs a purpose-built time-series database.