Bigtable for time-series data in GCP - Time & Space Complexity
When using Bigtable to store time-series data, it is important to understand how the time to read or write data changes as the amount of data grows.
We want to know how the number of operations grows when we add more time points.
Analyze the time complexity of writing multiple time-series data points to Bigtable.
// Pseudocode for writing time-series data points
for (int i = 0; i < n; i++) {
bigtable.write(rowKeyForTime(i), dataPoint(i));
}
This sequence writes n data points, each with a unique timestamp as the row key, into Bigtable.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Single write API call to Bigtable for each data point.
- How many times: Once per data point, so n times.
Each new data point requires one write operation, so the total operations grow directly with the number of points.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 write calls |
| 100 | 100 write calls |
| 1000 | 1000 write calls |
Pattern observation: The number of operations increases in a straight line as input size grows.
Time Complexity: O(n)
This means the time to write all data points grows proportionally with the number of points.
[X] Wrong: "Writing multiple points at once will take the same time as writing one point."
[OK] Correct: Each point requires a separate write operation, so more points mean more total operations and more time.
Understanding how data volume affects operation count helps you design scalable systems and explain your choices clearly in interviews.
"What if we batch multiple time-series points into a single write call? How would the time complexity change?"
Practice
Solution
Step 1: Understand Bigtable's design for data volume
Bigtable is designed to store very large amounts of data efficiently, especially for time-series data which grows quickly.Step 2: Recognize Bigtable's performance benefits
It offers fast read and write speeds, which is essential for time-series data that updates frequently.Final Answer:
It can handle large volumes of data with fast read and write speeds. -> Option CQuick Check:
Bigtable = fast, large data [OK]
- Confusing Bigtable with visualization tools
- Assuming Bigtable has built-in ML models
- Thinking Bigtable only stores JSON
Solution
Step 1: Review gcloud CLI syntax for Bigtable instance creation
The correct command uses 'gcloud bigtable instances create' with required flags for cluster, zone, display name, and instance type.Step 2: Compare options with correct syntax
gcloud bigtable instances create my-instance --cluster=my-cluster --cluster-zone=us-central1-b --display-name="My Instance" --instance-type=PRODUCTION matches the official syntax exactly, including cluster and zone flags.Final Answer:
gcloud bigtable instances create my-instance --cluster=my-cluster --cluster-zone=us-central1-b --display-name="My Instance" --instance-type=PRODUCTION -> Option DQuick Check:
Correct gcloud syntax = gcloud bigtable instances create my-instance --cluster=my-cluster --cluster-zone=us-central1-b --display-name="My Instance" --instance-type=PRODUCTION [OK]
- Using incorrect command verbs like 'create instance' or 'instances new'
- Missing required flags like --cluster-zone
- Confusing instance type flags
deviceID#timestamp, what will be the order of rows when scanned?Solution
Step 1: Understand Bigtable row key sorting
Bigtable sorts rows lexicographically by row key from left to right.Step 2: Analyze the key format deviceID#timestamp
Since deviceID is first, rows are grouped by deviceID, then sorted by timestamp ascending within each device.Final Answer:
Rows are ordered by deviceID first, then by timestamp ascending. -> Option AQuick Check:
Row key order = deviceID then timestamp [OK]
- Assuming timestamp sorts first
- Thinking rows are unordered
- Confusing ascending vs descending order
Solution
Step 1: Identify hotspotting from row key design
If timestamp is first in the key, writes concentrate on a small range causing slow queries.Step 2: Fix by changing row key order
Placing deviceID first distributes writes and reads better, improving performance.Final Answer:
Cause: Row keys are timestamp first causing hotspotting. Fix: Reverse the key to deviceID#timestamp. -> Option BQuick Check:
Hotspotting fix = reorder row key [OK]
- Thinking multiple clusters slow queries
- Adding column families improves speed
- Confusing data format impact on speed
Solution
Step 1: Consider query pattern for recent data per device
Queries often request recent data, so sorting recent timestamps first helps.Step 2: Use reversed timestamp in row key
Reversing timestamp (e.g., max - timestamp) sorts recent data at the top for fast access.Step 3: Group by deviceID first
This groups data by device, making queries per device efficient.Final Answer:
Use row keys as deviceID#reversed-timestamp to keep recent data first and group by device. -> Option AQuick Check:
Reversed timestamp + deviceID = fast recent queries [OK]
- Using timestamp first causes hotspots
- Storing all data in one row causes size limits
- Random UUID keys prevent efficient range scans
Ready to prove it?
Pass the test and this pattern moves unknown
