Library

Volume 1 · System Design Scenarios

Notebook
Sign in

Section 61

Large-Scale Daily File Fan-Out Problem (5GB Daily File Distribution)

620 words · about 3 min

Problem Statement

A ~5GB file arrives daily at a fixed time (e.g., 12:00) and must be loaded into two databases today (one SQL, one NoSQL) — with the expectation that more downstream consumers will be added later. A naive single API/script reading the whole file into memory will OOM, and hard-coding writes to N databases in one script creates unmanageable technical debt every time a new consumer is added.

Two Optimal Approaches (choose based on whether live services need to react in real time)

Approach A — Pure batch orchestration (ETL tool only), when nothing needs to react in real time: The 5GB file lands in Blob Storage/S3 at 12:00, triggering an orchestrated pipeline (Azure Data Factory / AWS Glue / Airflow). The pipeline’s Copy Data activity streams the file in parallel chunks (no OOM risk — the orchestrator is built for exactly this) and fans out to multiple configured sinks in a single pipeline run — one sink writes to the SQL database, another writes to the NoSQL database. Adding a third database next year means opening the pipeline and adding a third sink — zero code changes, pure configuration (Open/Closed Principle applied to a data pipeline).

Approach B — Hybrid pub/sub fan-out, when live microservices must react immediately (e.g., a billing engine or notification service needs each record as it’s processed): The orchestrator (ADF/Glue) is used strictly to safely shred and parse the massive file — never to write directly to the target databases. Instead, it publishes each parsed row/batch as an event onto a pub/sub topic (Service Bus Topic / SNS+SQS / Kafka topic). Independent, decoupled microservice subscribers react to that same topic: one subscriber owns SQL inserts, a completely separate subscriber owns NoSQL inserts, a third (added later, with zero change to the ingestion logic) might own real-time billing recalculation. This is the Open/Closed Principle applied at the architecture level — the core ingestion pipeline never changes when a new consumer is added; you only add a new subscriber.

Approach A (Batch fan-out):
5GB file -> Blob/S3 (12:00 trigger) -> ADF/Glue Pipeline
                                          |
                              Copy Data Activity (parallel stream, no OOM)
                                    |            |            |
                                    v            v            v
                                SQL Sink    NoSQL Sink   [Future Sink]
                                (config only, no code change to add)

Approach B (Pub/Sub fan-out):
5GB file -> Blob/S3 (12:00 trigger) -> ADF/Glue (shred + parse ONLY)
                                          |
                              Publish each row/batch as an event
                                          v
                              Service Bus Topic / Kafka Topic
                                    |            |            |
                            +-------+      +-----+      +-----+
                            v              v            v
                     SQL Subscriber  NoSQL Subscriber  Billing Subscriber
                     (independent,   (independent,     (added later, zero
                      own retry/DLQ)  own retry/DLQ)    change upstream)

Decision Criteria

Factor Favors Approach A (Batch) Favors Approach B (Pub/Sub)
Downstream consumers Fixed, known set (2-3 databases) Growing/unknown set, added by other teams over time
Real-time reaction needed No — daily batch is fine Yes — services must react as data lands, not next day
Team ownership Single data engineering team owns it all Multiple teams own their own subscriber independently
Operational complexity budget Lower — one pipeline to monitor Higher — topic + N independent subscribers to monitor

Failure Handling

  • Approach A: pipeline-level retry per activity; if the SQL sink fails but NoSQL succeeds, only the failed sink activity re-runs (idempotent upserts keyed by a natural/business key, not a straight insert, to make retries safe).
  • Approach B: each subscriber owns its own retry policy and dead-letter queue; a slow or failing NoSQL subscriber never blocks or slows down the SQL subscriber — this failure isolation is the primary architectural benefit of the pub/sub approach over the batch approach.
  • Both approaches: the file processing step itself is idempotent (safe to re-trigger for the same day’s file) — track a processing watermark/checksum so a retry doesn’t double-process.