Analytics query cost
Budget compute and scan separately
A fictional workload scans 20 decimal TB/month. At an illustrative $5/TB, scan compute costs $100. Another model charges $0.40 per capacity-unit-hour for 250 hours: also $100. Neither price is a provider quote. The break-even is 20 TB for this fixed number of hours; if usage doubles while capacity hours are unchanged, scan compute costs $200 while capacity compute remains $100, but the latter may queue or miss latency targets. Capacity reservations commit money or resources for a defined term, not unlimited throughput; estimate utilization, concurrency, scaling and idle time. BigQuery offers on-demand processed-data billing and capacity-based compute; its actual scan units can be TiB, not decimal TB. Redshift, Synapse and Fabric have distinct provisioned, consumption or capacity options. Verify selected SKU and billing dimensions. Add storage, ingestion, streaming compute, transfer, retention, backups and exports before comparing total cost. No live price or reservation recommendation is implied.
Model throughput, retention and transfer
Assume steady 2 MB/s of payload in decimal units for 24 hours: 2 × 86,400 / 1000 = 172.8 GB/day. Seven days retain 1209.6 GB of logical payload before compression, replicas, metadata or tier overhead. At hypothetical $0.02/GB-month the steady-state retained payload costs $24.192/month. Two independent full consumers each read 172.8 GB/day: 345.6 GB/day read volume; whether both reads incur charges depends on the product. If 300 GB/month crosses a chargeable boundary at $0.08/GB, transfer costs $24. A 3-unit processor running 720 hours at $0.10/unit-hour adds $216. Partition throughput can be limited by both bytes and records; use the larger required count after rounding up and check skew and aggregate quota. For fictional 8 MB/s and 3000 records/s with limits 2 MB/s and 1000 records/s per partition, max(ceil(8/2), ceil(3000/1000)) = 4 under perfectly even load. Real quotas and billing vary. See BigQuery pricing, Pub/Sub pricing, Dataflow pricing and Event Hubs tiers.
Run an event-time correction model
The following Python 3 model consumes an ordered list of arrivals, uses fixed-width windows, a toy watermark equal to the largest accepted event timestamp, and retains IDs in memory. An event is too late when the previous maximum reaches the window end plus allowed lateness. Identical replayed IDs count as duplicates; conflicting IDs raise an error. It returns final totals, late IDs and duplicate count; there is no real clock, broker, persistence, trigger or distributed watermark. The model uses integer cents and seconds. No credentials or external calls.
def windows(events, lateness=5, width=10): if width <= 0 or lateness < 0: raise ValueError("invalid window settings") seen, totals, late, duplicates = {}, {}, [], 0 maximum = None for event_id, ts, cents in events: if not event_id or type(ts) is not int or ts < 0 or type(cents) is not int or cents < 0: raise ValueError("invalid event") if event_id in seen: if seen[event_id] != (ts, cents): raise ValueError("conflicting event ID") duplicates += 1 continue seen[event_id] = (ts, cents) start = ts // width * width if maximum is not None and start + width + lateness <= maximum: late.append(event_id) continue maximum = ts if maximum is None else max(maximum, ts) totals[start] = totals.get(start, 0) + cents return sorted(totals.items()), late, duplicates
sample = [("a", 2, 300), ("b", 12, 500), ("c", 8, 200), ("a", 2, 300), ("d", 16, 100), ("e", 4, 400)]print(windows(sample))Expected output:
([(0, 500), (10, 600)], ['e'], 1)At arrival of c the maximum is 12, below window 0 end + 5 = 15, so c corrects the earlier total from 300 to 500. The repeated a is ignored. Arrival d advances maximum to 16, so e is too late for window 0 and is recorded for reconciliation. The windows are half-open. Rerunning the same full input reproduces the totals; rerunning a suffix alone does not recover previous state. Production state must preserve watermark, checkpoint and deduplication semantics across restarts, bounded by retention; state expiry must be compatible with replay. A sink should upsert by window/key/version, not blindly append a corrected total. This toy watermark is unsuitable for idle or delayed partitions; actual engines estimate progress across sources.
Control query spend and quality
Use projections rather than SELECT * where possible, restrict date ranges, partition or cluster based on access patterns, pre-aggregate common reports, and inspect explain plans or platform dry-run estimates where supported. Cache only when correctness and freshness permit. A LIMIT after a scan is not a reliable scan cap. Set query limits, budgets and workload isolation; alerts alone are not hard spending caps. Monitor query volume, data processed, slot or unit hours, queue delay, ingestion bytes, consumer lag, replay amplification and transfer. Choose capacity after observing concurrency and peak workload, not only average usage. A warehouse report must reconcile with the authoritative ledger; compare totals by event day and publish freshness, late-event policy and version. Report missing data explicitly rather than showing a plausible zero.
Governance and access tests
Grant the ingestion identity write access only where required, processing identity read access to approved source and write access to target, and analysts access to authorized views or tables. Row restrictions control which records are visible; column controls or masking protect sensitive fields. Direct raw-file, export, backup and stream-consumer permissions are separate paths that may bypass SQL-level policies. Test permitted aggregate access, forbidden raw reads, forbidden cross-tenant rows and forbidden sensitive columns in each actual service before rollout. Separate analyst and administrator privileges, audit policy changes and data export, encrypt data, and classify retention requirements across topic, checkpoint, warehouse and backup. Avoid sensitive payloads in logs or quarantine metadata. The local exercises verify arithmetic and processing semantics, not access enforcement. BigQuery row security, column security, and Dataflow permissions illustrate service-specific controls. Record actual authorization test evidence before claiming governance is enforced.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Analytics query cost — knowledge check
Choose the best answer for each offline scenario.
At fictional $5/TB, what does 20 TB cost?
Which event belongs in [10,20)?
What does a corrected window output need?
Why check direct object access?
Which cost belongs in a complete comparison?