Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Shopify Engineering 7 min read How-to mediumAdept

3 (More) Tips for Optimizing Apache Flink Applications

Three practices for tuning large stateful Apache Flink jobs, drawn from Shopify's streaming platform. Size parallelism so task managers × slots per task manager is equal to or slightly above the highest operator parallelism (e.g. 25 TMs × 4 slots for parallelism 100), starting with a single environment-level value. Prevent sink backpressure with batched writes (Kafka batch.size, Bigtable bulk mutations) and fix keyBy skew by appending a random bucket to hot or low-cardinality keys, then re-aggregating. Use HybridSource to present archived object-storage data and live Kafka topics as one ordered DataStream, which also speeds backfills because the archives have far more partitions.

Related posts

  • 7 Tips For Optimizing Apache Flink Applications

    Shopify Engineering mediumAdept

    Lessons from running large stateful Apache Flink jobs (up to 13 TB of state) on GKE with the RocksDB state backend and checkpoints on GCS. Disabling Kryo fallback and fixing the serialization failures it exposed, such as Scala BigDecimal and sealed-trait ADTs, raised throughput by 20%. Keying records by partition before the File Sink cut active buckets per Task Manager by 90% and ended heap OOMs, and local SSDs for RocksDB gave about a 10x processing speedup over NFS. Further tips cover separate config profiles for backfill and steady state (partitions, network buffers, checkpoint intervals), avoiding dynamic classloading to stop Metaspace leaks on restart, and profiling with async-profiler, VisualVM, jemalloc/jeprof and Eclipse MAT.

  • From Homegrown to Flink: Migrating a Stateful Ad Event Join at Scale

    Zalando Engineering hardMaster

    Zalando's Ad Platform team replaced a 7-year-old homegrown Java service that joins ad auction (bid) events with user interaction events within a 15-minute window with an Apache Flink pipeline using RocksDB state and incremental checkpoints. Flink's built-in interval join spent 15-30% of CPU on RocksDB seeks and maintained a ~70M-entry timer queue, so the team wrote a KeyedCoProcessFunction with two ValueStates keyed by unique bid ID and TTL-based compaction cleanup, cutting the join operator from 30-60 subtasks and 150-300GB memory to 10 subtasks and 50GB. The post also covers RocksDB compaction tuning to stop state growth, a custom Kinesis deaggregation layer, Enhanced Fan-Out throttling issues, Karpenter evicting pods during Flink rescales, kernel OOM kills fixed by raising JVM overhead and lowering managed memory, and a four-week shadow pipeline plus A/B test before cutover.

  • Scaling Shopify's BFCM Live Map: An Apache Flink Redesign

    Shopify Engineering mediumAdept

    Shopify scaled its Black Friday/Cyber Monday live sales map by putting Apache Flink in front of Cricket, its home-grown Go stateful streaming service. Flink filtered the checkout Kafka stream so Cricket processed only about one percent of the events, and Flink also computed new metrics such as product trends and unique shoppers. The Flink jobs used cross-region sharding and active-active deployment, handled load tests of 1M events/sec and ran with 100% uptime through BFCM, with Spark batch jobs as a fallback. Redis used for broadcasting to browsers still became a bottleneck and briefly clogged in production, so the planned redesign moves all metrics into Flink and snapshots them to a store that a web tier serves from an in-memory cache.

  • Why We Ditched Flink Table API Joins: Cutting State by 75% with DataStream Unions

    Zalando Engineering hardMaster

    Chained Flink 1.20 Table API/SQL joins amplified state because each join operator keeps its own copy of upstream records in RocksDB, pushing Zalando's Product Offer Enrichment jobs to about 240GB of state. Hourly savepoints then pinned CPU at 100%, caused backpressure, crash-restart loops and failed snapshots, and forced 10–20% overprovisioning on AWS Managed Flink. Replacing the join chain with a union of all streams into one DataStream, processed by a single keyed process function holding one ValueState per SKU with timestamp-based filtering and deduplication, cut state to 56GB and snapshot time from 11 to 2.5 minutes. AWS cost fell only 13%, because KPU billing tracks CPU and memory rather than state size. The same idea ships in Flink 2.1 as the experimental Multi-Way Join operator.

  • Rerouting the Stream: How Lyft Moved to the Apache Flink Kubernetes Operator

    Lyft Engineering mediumAdept

    Lyft retired its homegrown Flink Kubernetes operator and moved hundreds of streaming jobs to the open-source Apache Flink Kubernetes Operator. To avoid rewriting every config, a translation layer in the deploy API converts the legacy FlinkApplication CRD into a FlinkDeployment, and dynamic config allows per-app migration and instant rollback. Getting the full benefit took follow-on work. Deploys caused 3–20 minutes of downtime until FlinkBlueGreenDeployments was adopted. Upgrading to Flink 1.19 enabled in-place autoscaling and Kinesis backlog metrics. Autotuning reclaimed memory that Beam Python harnesses had been hiding in JVM overhead, which OOM-killed TaskManagers until the harness moved to a sidecar. Because autotuning requires restarts, critical jobs use in-place autoscaling only, while other jobs use both features. Variable pod sizes then pushed Lyft to Karpenter and most-allocated scheduling to cut unused spend.

The quest for software engineering knowledge.

Look:
Layout: