Building Petabyte Scale Data Platforms
Building Petabyte Scale Data Platforms
By: Mayur, Navdeep
This is what you will get by the end of the day:
- A WebServer endpoint that can consume up to 1 million events per second. - A Kafka cluster (speed layer) — containing your last 30 days (configurable) of incoming data. - Ephemeral Spark clusters spawned periodically, completing aggregations and dumping data to S3 (Parquet/HUDI), Redshift, and caches (Redis, DynamoDB), then destroying themselves. - An S3 data lake (warm layer), carefully partitioned on low-cardinality columns, queryable via Athena, Redshift, EMR, or a Pandas notebook on your laptop. - A Redshift cluster (hot layer) acting as a cache for the warm layer and storage for semi-aggregations. - A CDC capture layer — capturing any change in your database (CRUD), pushing it into Kafka, and recreating current DB-table state in S3 (any WAL-compliant database), queryable via Athena/EMR/Redshift — say bye-bye to expensive replicas. - And above all, everything configured and spawned with Infrastructure as Code in less than 15 minutes.
Let's look at each component to understand the Why, Where, and How.
WebServer Endpoint
Why → HTTP is the most common and easy way to send information to a server. Authentication-enabled web servers receive JSON/Protobuf messages from clients across the world. Clients shouldn't need to handle the complexity of pushing data — they just fire and forget.
What → A Golang WebServer running inside a container orchestrated via Fargate/Kubernetes. It receives messages from clients and asynchronously pushes them to Kafka (or any highly scalable queue), with buffering in memory and on disk.
How → WebServers deployed on Fargate/K8s, autoscaling on tunable properties like RPM, CPU, or memory. They are extremely light on resources — a normal 1 GB RAM, 1 CPU pod can handle ~2000 concurrent requests and ~40k requests per minute. A 10-pod cluster handles a million requests per minute (benchmarks go up to 2 million events per second).
Optimizations
These are some important tweaks we have made to handle spikes or failures:
- Disk-based buffering → WebServers buffer to disk and push to Kafka in a controlled manner. Spikes can compromise Kafka, and we don't want to spend money configuring Kafka for every possible peak. - WebServers use LevelDB-based disk queues for intermittent buffering. On graceful shutdown, the remaining disk-queue data is pushed to Kafka aggressively. - Whether the signal is graceful shutdown or SIGKILL, we use persistent volumes in EKS to make the buffer fault-tolerant and reusable.
From here, we can assume the data is available in Kafka.
Kafka Cluster
We will briefly discuss this since we use AWS MSK or Confluent-managed Kafka. We have used serverless versions of both, but they become more expensive than provisioned ones above ~50M monthly events.
Why → It's the speed layer. It decouples producer and consumer, is a valid storage layer, and makes data available as soon as practically possible (typically ~100 ms). We use it for real-time apps like "continue watching" in OTT platforms, security triggers, and 5-minute near-real-time aggregations.
What → We don't ask collaborators to spawn large clusters. Because WebServers buffer events, even a 1-million-events-per-second peak can be absorbed by a mild 3-node Kafka cluster.
One caveat: retention. Kafka shows grumpy faces when replaying very old data — its real performance comes from page cache, which is mostly valid for recent data. We recommend 3 to 7 days of data in Kafka; older data should be replayed from S3.
Kafka is just a queue we prefer — not mandatory. We have used SQS and GCP Pub/Sub for the same use case.
Spark Clusters
This is where the meat of the solution is — real munching happens here. We leverage Hadoop-based solutions from different cloud providers: EMR on AWS, Dataproc on GCP.
Our twist ensures extremely low operational and maintenance cost: we keep our Spark clusters serverless — stateless, spawned when required, and destroying themselves when done. This achieves:
- No maintenance of always-on clusters. - Complete isolation of data and compute: data and metadata live entirely outside the cluster.
This is only possible in the public cloud, where we can ask for any resource on demand. The downside of separating compute and storage is some read/write latency — but we've come around the problem (more below).
Jobs we run
- Simple dumps → dumping Kafka data as-is to S3 (the definition of a data lake). - Semi-aggregations → where things get interesting. We partition by time and store semi-aggregations. For example, total sessions per hour can be rolled up into any aggregation across a day, month, or year.
What these jobs comprise
SQL is the most common language in our Spark jobs:
- Easier to explain and reproduce. - SQL is still the most common medium for analytics, CRUD, and ETL across all domains. - Spark code generation — when SQL is used, Spark infuses generated code that improves performance by orders of magnitude. See [Whole-Stage CodeGen](https://jaceklaskowski.gitbooks.io/mastering-spark-sql/content/spark-sql-whole-stage-codegen.html). - All SQLs are Hive-compliant — the same query works in Athena, Hive (via EMR), Redshift Spectrum, and Presto.
Special mention: HUDI
HUDI (Hadoop Update Delete Insert) from Uber is one of the central pillars of our architecture. It enables near-ACID behavior on S3 — huge in the big-data world where we often default to append-only for performance.
A little more about HUDI:
- A Spark library leveraging multi-version concurrency control (MVCC) to maintain multiple versions of an ingestion. - Versions can be combined/picked during ingestion or reading. - Self-compacts versions on ingestion. - Provides an interface to combine records (currently only in JVM-based languages). - With the HUDI index (no server, kept in the filesystem), the library knows which part of the data (directory or file) to update or version.
In short, it does what an OLTP engine does behind the scenes for upserts.
How we use HUDI:
- Most files we write (except the raw data lake) are HUDI-compliant. - We use HUDI to store CDC data, store metrics, and enable point-in-time queries.
Schema Store
One of the most important aspects of the Spark cluster is the Schema Store:
- Spark SQL uses it to query or store data in external S3-backed tables. - The same schema is available to Athena and Redshift.
Our clusters are now pure compute — nodes are used purely for processing, schema lives externally in Glue, and data lives in S3. We use cloud-native schema stores: AWS Glue and GCP Cloud Storage catalog (a managed Hive).
Orchestrator
No batch or big-data workload is complete without an orchestrator — in our case, this is another central pillar.
Why — the orchestrator is responsible for:
- Creating EMRs. - Meta actions: enriching Hive partitions, creating future directories, copying relevant jars to the Spark classpath. - Embedding steps into EMR. - Any ancillary actions required for Spark jobs. - Command-line execution for Spark, Hive, and Presto in remote clusters.
Our orchestrator is simple and highly abstracted:
- Leverages cloud crons like AWS EventBridge and GCP Cloud Scheduler. - Completely isolated from the execution environment — actions run inside Lambda. - Practically no scaling limit and almost no cost.
What — the process is simple:
- We define a cron and an associated Lambda via our cron-lambda Terraform module. - Lambda code is the same, but the environment passed in decides which job to run. - Lambda is triggered by EventBridge. - Lambda creates an EMR with embedded AWS Steps. - Steps execute and the EMR kills itself. - How many jobs to batch or run in parallel is defined by an easy-to-configure YAML file.
Advantages of this setup
- Pure-code pipeline. - Trigger, initiator, and actions are all separate and abstracted. - Actions can be triggered by EventBridge but can also be invoked from UI or CLI by calling the Lambda — so ad-hoc runs are trivial. - Runs at almost no cost (the generous Lambda free tier is effectively lifetime-enough for this setup).
Cost
We will consider a use case with a decent volume of 10 GB per hour (1 stream/table). Running the job hourly:
- ~$310 per month for EMR operations. - Kafka — since we use it for multiple purposes, the cost is hard to attribute fully to this platform, but the cheapest fault-tolerant, prod-traffic-handling Kafka costs around $350/month (less with reserved instances).
So for ~10 GB per hour, your monthly cost is around $600–$700 (including Kafka). This pipeline scales comfortably to tens of TB per hour by scaling Kafka or the EMR cluster. We run 90% of our EMR nodes on spot instances.
Our pipeline already runs for enterprises like Quickheal and Helpshift, startups like Dyte.io, Numberz, and multiple Indian government entities like ONDC and NIC. The greatest compliment we have received is "is it still running??" — and we have responded with what we have always wanted to say to business teams: "Focus on getting more from data, forget the platform."
---
At Dataorc we design solutions with scale and cost-effectiveness in mind. With experience building petabyte-scale data platforms and 50k TPS portals from scratch for enterprises and startups, we believe in solutions that grow with your business. Reach out for a free open-consulting session with our tech team — about this, or anything data.