Data Ingestion
Designing and building reliable pipelines to move data from source systems into GCP storage and analytics services.
Cloud 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
- Streaming: Pub/Sub → Dataflow → BigQuery (streaming inserts or Storage Write API). Use for low-latency, continuous data.
- Batch: GCS files → Dataflow → BigQuery (load jobs). Use for periodic bulk loads where latency tolerance is minutes-to-hours.
- Micro-batch: Pub/Sub → Dataflow → GCS (windowed file writes) → BigQuery load jobs. Balances cost and latency.
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 Dataproc 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.
Cloud 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