When a single bottleneck threatens end-to-end availability, use Spark Structured Streaming with bounded watermarks, checkpointed foreachBatch Iceberg MERGE INTO for exactly-once Silver upserts, and background bin-pack compaction to prevent small-file explosion.
TL;DR30-second simplified summary▾
Core Mechanics: Modern BI dashboards and ML feature stores require fresh, deduplicated data (<= 2 min Bronze-to-Silver freshness) at 100,000 events/sec (bursting to 300,000 events/sec).
Visual & Structural Flow: Depicts Kafka -> Bronze (Append) -> Silver (Watermark + Iceberg MERGE) -> Gold (Kafka 300k/s -> Spark Streaming -> Iceberg Silver -> Compaction); 30s Micro-Batch Commit & Compaction Flow (Kafka -> Spark Driver -> Executors -> Iceberg Catalog).
Trade-Offs & Production: A naive pipeline runs df.writeStream.format('parquet').start('s3://silver/'): No Upserts or GDPR Deletes: Parquet files are immutable; CDC updates and row-level deletes require rewriting entire partitions manually. Enterprise Lakehouses pair Spark Structured Streaming with Apache Iceberg (or Delta Lake): Bronze: Append raw Kafka payloads with kafka_offset and ingest_ts every 30 s.
Failure Modes & Application: The Bronze/Silver/Gold Lakehouse pattern unifies streaming and batch analytics: ML Feature Stores: Serving < 2 min fresh user-session aggregates for real-time fraud and ranking models.
Why a Real-Time Medallion Lakehouse matters at 100k+ events/sec.
Why this matters: The mechanism: understand how Why a Real-Time Medallion Lakehouse matters at 100k+ events/sec works from first principles.
Think of Why a Real-Time Medallion Lakehouse matters at 100k+ events/sec as the intuition layer for Design a Real-Time Lakehouse & Medallion Pipeline: The mechanism: understand how Why a Real-Time Medallion Lakehouse matters at 100k+ events/sec works from first principles.
Modern BI dashboards and ML feature stores require fresh, deduplicated data (<= 2 min Bronze-to-Silver freshness) at 100,000 events/sec (bursting to 300,000 events/sec). Traditional nightly batch ETL is hours too slow, while writing raw Kafka streams directly to object storage without table-format ACID transactions produces duplicates, broken schemas, and unqueryable small files.
What happens without watermarks, ACID upserts, and compaction.
Why this matters: The problem: see what breaks without What happens without watermarks, ACID upserts, and compaction under real concurrency or scale.
Streaming directly into raw Parquet on S3/GCS causes three cascading data failures:
- Duplicate Silver Rows: Micro-batch retries after an executor crash append duplicate records unless upserts are idempotent.
- Small-File Explosion: Writing 30-second micro-batches across 200 partitions creates ~17M tiny files/month, crushing S3
LISTand query planning. - Unbounded State OOM: Deduplicating
event_idwithoutwithWatermark()grows RocksDB/JVM state indefinitely until executors OOM.
Kafka -> Bronze (Append) -> Silver (Watermark + Iceberg MERGE) -> Gold
1.Bronze Layer: Raw immutable append with Kafka offset metadata for replay.
2.Watermark Dedup: Bounds state store memory by dropping late keys past the 10-min window.
3.Iceberg MVCC: Atomic snapshot commits in foreachBatch guarantee exactly-once Silver.
4.Async Compaction: Rewrites small micro-batch files into 512 MB Parquet targets.
Iceberg MVCC snapshots + Spark checkpoints provide exactly-once upserts while async compaction keeps S3 read latency fast.
- Problem
- How to implement Design a Real-Time Lakehouse & Medallion Pipeline without hitting unbounded tail latency, state divergence, or operational fragility.
- Naive Solution
- Use a single unpartitioned path with unbounded retries and synchronous global coordination.
- Why It Fails
- Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
- Alternatives
- Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
- Engineering Decision
- When a single bottleneck threatens end-to-end availability, use Spark Structured Streaming with bounded watermarks, checkpointed foreachBatch Iceberg MERGE INTO for exactly-once Silver upserts, and background bin-pack compaction to prevent small-file explosion.
- Trade-Offs
- Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
When Design a Real-Time Lakehouse & Medallion Pipeline experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?
Naive solution (and why raw Parquet append breaks).
Why this matters: The problem: see what breaks without Naive solution under real concurrency or scale.
A naive pipeline runs df.writeStream.format('parquet').start('s3://silver/'):
- No Upserts or GDPR Deletes: Parquet files are immutable; CDC updates and row-level deletes require rewriting entire partitions manually.
- At-Least-Once Duplicates: Task retries leave partial/duplicate files visible to readers.
- Schema Breakage: Adding a new JSON field crashes downstream BI queries.
Naive solution (and why raw Parquet append breaks)
- No backpressure on spikes
- Implicit shared state
- Cascading tail latency
- Explicit capacity budgets
- Isolated failure domains
- Predictable p99 latency
Enterprise solution: Spark Structured Streaming + Apache Iceberg + AQE.
Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.
Enterprise Lakehouses pair Spark Structured Streaming with Apache Iceberg (or Delta Lake):
- Bronze: Append raw Kafka payloads with
kafka_offsetandingest_tsevery30 s. - Silver: Apply
withWatermark('event_ts', '10 minutes')+dropDuplicates(['event_id']), then executeMERGE INTOinsideforeachBatchusingcheckpointLocationfor exactly-once commits. - Maintenance & Governance: Run periodic
rewrite_data_files(bin-pack to512 MB),expire_snapshots, and Iceberg time-travel / GDPR row-levelDELETE.
30s Micro-Batch Commit & Compaction Flow
Readers see atomic Iceberg snapshots only after MERGE commits, preventing dirty reads or duplicate rows.
query = (silver_df.writeStream
.foreachBatch(upsert_to_iceberg_silver)
.option('checkpointLocation', 's3://checkpoints/silver_orders')
.trigger(processingTime='30 seconds')
.start())
StreamingQuery query = silverDf.writeStream()
.foreachBatch((batchDf, batchId) -> upsertToIceberg(batchDf, batchId))
.option("checkpointLocation", "s3://checkpoints/silver_orders")
.trigger(Trigger.ProcessingTime("30 seconds"))
.start();
Where Real-Time Medallion Lakehouses are used.
Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.
The Bronze/Silver/Gold Lakehouse pattern unifies streaming and batch analytics:
- ML Feature Stores: Serving
< 2 minfresh user-session aggregates for real-time fraud and ranking models. - E-Commerce Order & Inventory BI: Merging Debezium CDC streams into queryable Iceberg tables with time-travel audits.
- GDPR / CCPA Compliance: Executing row-level deletes across petabyte object storage without full-table rewrites.
Practice: Make the trade-off yourself.
Why must a streaming Silver pipeline pair Iceberg MERGE INTO with a Spark watermark and background file compaction?