Data Ingestion
Designing and building reliable pipelines to move data from source systems into GCP storage and analytics services.
Pub/Sub
Pub/Sub is GCP's fully managed, real-time messaging service. It decouples producers from consumers and guarantees at-least-once delivery. Key exam concepts:
Core Concepts
- Topics & Subscriptions: Publishers send messages to a topic; subscribers pull (or push) from a subscription attached to that topic. Multiple subscriptions on the same topic enable fan-out.
- Ordering: By default, Pub/Sub does not guarantee ordering. Use
ordering_keyto enforce ordering within a key partition. - Exactly-once delivery: Pub/Sub supports exactly-once delivery on the subscription side (pull only). This is distinct from Dataflow's exactly-once processing semantics.
- Dead-letter topics: Messages that can't be processed after N attempts get routed to a dead-letter topic for later inspection.
- Message retention: Default 7 days; configurable up to 31 days. Subscribers can seek/replay to a timestamp or snapshot.
When to Use Pub/Sub
- Streaming event ingestion (clickstream, IoT, logs)
- Decoupling microservices
- Buffering between ingestion and processing (Pub/Sub → Dataflow)
- Fan-out to multiple downstream consumers
Dataflow for Ingestion
While Dataflow is primarily a processing engine, it's often the ingestion layer too — reading from Pub/Sub, Kafka, files, or databases and writing to BigQuery, Bigtable, or GCS.
Batch vs. Streaming Patterns
Click (or tab to) any component below to see why it's used in that pattern instead of the alternative.
Streaming — use for low-latency, continuous data:
-
Absorbs continuous events with no fixed schedule to batch against, and durably retains them so a downstream outage never loses data.
-
Reads continuously and writes each event through as it arrives — there's no batch to wait for.
-
Trade-off: streaming inserts or the Storage Write API make the row queryable within seconds — but cost ~$0.01/200 KB (see the cost note below). That's the price of low latency.
Batch — use for periodic bulk loads where latency tolerance is minutes-to-hours:
-
Files already land in GCS on a schedule — there's no continuous stream to buffer, so Pub/Sub adds nothing here.
-
The same Beam pipeline code runs in batch mode — reads the whole file set, transforms it, and finishes, rather than running forever.
-
Trade-off: load jobs are free — that's the saving the cost note below describes — but you give up the near-instant latency that streaming inserts buy you.
Micro-batch — balances cost and latency:
-
Same reason as the streaming pattern: events still arrive continuously and need to be absorbed.
-
Instead of writing each event straight to BigQuery like the streaming pattern does, Dataflow groups events into fixed time-window files first.
-
This extra stop is what the streaming pattern skips — it's also what makes the next step a free load job instead of a paid streaming insert.
-
Trade-off: free, like the batch pattern — but the window is minutes, not hours, so data lands sooner than a full batch run would.
Other Ingestion Services
Datastream (CDC)
Serverless change data capture (CDC) service. Reads from MySQL, PostgreSQL, Oracle, and AlloyDB, and streams changes into BigQuery, GCS, or Cloud SQL. Ideal for database replication and real-time analytics on operational data.
Cloud Data Fusion
Visual, code-free ETL/ELT tool built on CDAP. Best for teams that need a GUI-based pipeline builder. Supports 200+ connectors. Runs on Managed Service for Apache Spark under the hood.
Storage Transfer Service
Managed service for bulk data transfers from AWS S3, Azure Blob Storage, on-prem filesystems (via agent), or HTTP/HTTPS sources into GCS. Supports scheduled and recurring transfers.
Transfer Appliance
Physical device for migrating petabyte-scale data to GCS when network transfer is impractical. Shipped to your data center, loaded, and shipped back.
Bigtable — Schema & Ingestion
Bigtable is a high-throughput, low-latency NoSQL database ideal for time-series, IoT, and analytics workloads. Row key design is the single most important decision.
Row Key Design Principles
- Avoid hotspotting: Sequential keys (timestamps, auto-increment IDs) concentrate reads/writes on a single tablet. Use hashing, salting, or field reversal.
- Support query patterns: Data is stored lexicographically by row key. Design keys so your most common queries are prefix scans.
- Composite keys: Combine fields with
#delimiters, e.g.hash#deviceId#timestamp.
Practice Questions — Data Ingestion
deviceId#timestamp. You're observing hotspotting on recently deployed devices that have sequential IDs. How should you redesign the row key?
deviceId string and use reversedDeviceId#timestamp as the row key
deviceId (e.g., first 2 bytes of MD5) to create hash#deviceId#timestamp, and use a separate Bigtable table with row key region#timestamp#deviceId for regional queries
timestamp#deviceId as the row key so that time-based regional scans are efficient
deviceId with leading zeros and add a random salt prefix like salt#deviceId#timestamp
deviceId distributes writes evenly across tablets, eliminating hotspotting while still allowing single-device lookups (since the hash is reproducible). A separate table with region#timestamp#deviceId as the row key efficiently supports the regional scan pattern. Option A (reversing the ID) only partially helps and doesn't address regional queries. Option C (timestamp prefix) creates severe write hotspotting on the most recent timestamp. Option D (random salt) makes reads impossible without scanning all salts.
pg_dump export to GCS followed by a BigQuery load job, but the 24-hour data staleness is unacceptable. You need data freshness under 5 minutes with minimal impact on the source database. What should you use?
pg_dump frequency to every 5 minutes and automate it with Cloud Scheduler