6 minute read

A framework benchmark is useful only if readers can reconstruct the workload, compute envelope, input, and checks. A table that says “Flink is 30 percent faster” without exposing serialization, windowing, sink behavior, and failure policy is a vendor anecdote, not a performance result.

This article defines one stateful streaming workload, one correctness oracle, and a harness that runs Beam, Spark Structured Streaming, and Flink under equal resource ceilings. The numbers below are an illustrative baseline for the described envelope; they are not a universal ranking. Your Kafka version, Beam runner, JVM, network, shuffle implementation, and actual event distribution will move the result.

Illustrative throughput, latency, and recovery chart

Benchmark contract

The workload converts payment events into one-minute account totals and emits a late-data-adjusted result:

{
  "event_id": "1:84291",
  "account_id": "account-0091",
  "amount_cents": 12900,
  "currency": "USD",
  "event_epoch_ms": 1630339200017,
  "producer_epoch_ms": 1630339200041
}

The generator creates:

  • 200 million events in a fixed seed;
  • 12 Kafka partitions and 1 million distinct accounts;
  • a 1 KiB average JSON record including padding;
  • 80 percent on-time events and 20 percent with 0 to 120 seconds of lateness;
  • a reproducible five percent duplicate rate;
  • a Zipf key distribution with exponent 0.8;
  • five one-minute windows per account in the steady-state stream.

Correctness is one output per (account_id, window) after the watermark, with an exact sum, event count, and last-seen version. This is intentionally stateful and requires event time, dedupe, grouping, and window finalization. A stateless word count would miss the most meaningful differences.

Environment envelope

Run every system on the same dedicated Kubernetes worker pool:

cluster:
  worker_nodes: 8
  worker_shape:
    cpu: 8 vCPU
    memory: 32 GiB
    local_ssd: 300 GiB
  network: 10 Gbit/s
  jvm: OpenJDK 11
  kafka_brokers: 3
  kafka_partitions: 12
  replication_factor: 3
framework:
  total_job_cpu: 32
  total_job_memory: 96 GiB
  kafka_consumer_group: benchmark-<framework>-<run-id>
  output: JDBC idempotency table
  checkpoint_interval: 30s

Reserve Kafka and the results database on separate nodes. Do not count their CPU inside the framework ceiling. Pin the same exact container digest and disable automatic dependency updates. Record the framework, Java, Scala, connector, Kafka client, OS image, and configuration digests in the run manifest.

Generate deterministic input

A small generator should write the same event IDs and timestamps regardless of framework run:

long accountNumber = sampleZipf(seed, ACCOUNT_COUNT, 0.8);
long windowBucket = eventNumber / eventsPerMinute;
long baseTime = startEpochMs + (eventNumber * intervalNanos / 1_000_000);
long lateMs = rng.nextDouble() < 0.20
    ? rng.nextInt(121) * 1000L
    : 0;
String eventId = "run-17:" + eventNumber;
long eventTime = baseTime - lateMs;
int partition = Math.floorMod(eventId.hashCode(), 12);

Commit an immutable input topic per benchmark release and retain it for at least the full test plus warmup. Use compact JSON consistently. Do not stream-generate a source for one system and replay a pre-generated Kafka topic for another: producer backpressure would become part of the result.

Bootstrap Kafka with an explicit topic definition:

kafka-topics.sh --bootstrap-server kafka:9092 \
  --create --topic benchmark-events-v17 \
  --partitions 12 --replication-factor 3 \
  --config retention.ms=86400000 \
  --config min.insync.replicas=2

Load it once:

./benchmark-generator \
  --bootstrap-server kafka:9092 \
  --topic benchmark-events-v17 \
  --events 200000000 \
  --partitions 12 \
  --seed 20210830 \
  --rate 250000 \
  --duplicate-rate 0.05

Keep the logical job equivalent

Each implementation performs the same stages:

  1. parse and reject malformed JSON;
  2. assign event time from event_epoch_ms;
  3. generate a one-minute event-time window;
  4. deduplicate event_id within the maximum two-minute late horizon;
  5. key by account_id;
  6. sum amount_cents and count accepted events;
  7. emit once at finalization;
  8. write with a unique (account_id, window_end) key.

Deduplication is stateful and must survive checkpoints. The source retention and dedupe horizon must cover the same event universe. For Beam, use a DoFn with keyed state if the selected runner supports it, followed by fixed windows and a combine. For Flink, use keyed process state plus event-time timers. For Spark 3.1, use withWatermark(...).dropDuplicates("event_id"); that version must retain event time in the streaming row for watermark-based state cleanup. Later releases may expose more explicit APIs, but document the release-specific behavior rather than using a whole-query dedupe state with different retention.

Use one output semantics for all systems: stage per checkpoint/batch identifier and transactionally MERGE by the result key. Do not benchmark a Flink Kafka transactional sink against a Spark filesystem sink and call that an engine comparison. Sink-specific test runs can be separate.

Example process controls

Launches should resolve to the same 32-vCPU and 96-GiB aggregate ceiling:

# Flink
flink run-application \
  -Dparallelism.default=12 \
  -Dtaskmanager.numberOfTaskSlots=4 \
  -Dtaskmanager.memory.process.size=8192m \
  -Dstate.checkpoints.interval=30000 \
  -c com.example.PaymentBenchmark \
  s3://benchmarks/apps/payment-flink.jar \
  --run-id run-17
# Spark
spark-submit \
  --master k8s://https://kubernetes.default.svc \
  --conf spark.kubernetes.container.image=registry/payment-benchmark:spark-3.1.2 \
  --conf spark.executor.instances=6 \
  --conf spark.executor.cores=5 \
  --conf spark.executor.memory=14g \
  --conf spark.sql.shuffle.partitions=120 \
  s3://benchmarks/apps/payment_spark.py --run-id run-17
# Beam Dataflow/Flink-style runner invocation
java -jar payment-beam.jar \
  --runner=FlinkRunner \
  --flinkMaster=flink-jobmanager:8081 \
  --parallelism=12 \
  --checkpointingInterval=30000 \
  --runId=run-17

The Beam row measures a specific Beam SDK, runner, version, and runner configuration. Beam’s DirectRunner is not a production benchmark. A Beam-on-Flink result is useful for model/runner overhead; it is not a clean independent measurement of Flink’s raw API.

Measure more than headline throughput

The harness records:

  • correctness: accepted unique input count, final keys, malformed count, duplicate suppression, and aggregate hashes;
  • throughput: committed events per second over steady state, excluding warmup;
  • latency: p50, p95, and p99 event arrival to final output after watermark;
  • resources: CPU cores, memory working set, GC pause, shuffle/state bytes, network, and storage IOPS;
  • recovery: time from process kill to restored full throughput and number of replayed records;
  • cost proxy: worker core-seconds and memory-GiB-seconds per successful million events.

Use framework-native metrics for debugging, but export all results to a common Prometheus schema:

benchmark_events_processed_total{framework,run}
benchmark_watermark_lag_seconds{framework,run,quantile}
benchmark_worker_cpu_seconds_total{framework,run}
benchmark_checkpoint_bytes{framework,run}
benchmark_recovery_seconds{framework,run}

Start a failure after the input has reached a stable phase. Kill one worker, then a job manager/driver in separate trials. A failure at startup is not the same state/recovery exercise as a failure with hundreds of GiB of state.

Illustrative baseline

These synthetic sample numbers assume eight 8-vCPU/32-GiB workers, 32 aggregate job vCPUs, 96 GiB job memory, 12 partitions, and the workload above. They are included to demonstrate the reporting shape, not as independently measured claims.

Framework configuration Steady events/s p95 final latency Peak worker memory CPU utilized Kill recovery Correctness
Flink 1.13, DataStream API 184,000 41 s 71 GiB 27.4 cores 53 s 200 unique M, exact
Spark 3.1, Structured Streaming 161,000 55 s 86 GiB 29.1 cores 78 s 200 unique M, exact
Beam 2.32 on Flink 148,000 63 s 79 GiB 28.7 cores 67 s 200 unique M, exact
Beam 2.32 on Dataflow-like managed runner* not run not run not run not run not run n/a

* A managed service would require a separately documented billable service envelope and cannot be compared by merely matching worker count.

The useful conclusion from this baseline is not that one framework “wins.” On this shaped stateful job, Flink’s event-time DataStream path has less end-of-window latency and lower peak memory. Spark spends more memory and shows micro-batch completion tails. Beam adds runner translation and state adapter overhead in this configuration. A different checkpoint backend, batch interval, Spark adaptive shuffle release, Beam transform implementation, Flume/network topology, or key distribution can reverse some of these gaps.

Fairness and validity checks

Repeat each run at least five times with a cold cache and rotate run order to control cluster thermal and noisy-neighbor effects. Report median and interquartile range, not only the best run. Reject a run if:

  • final counts or hashes differ from the oracle;
  • p95 is reported from only a subset of partitions;
  • the framework exceeds the common CPU or memory ceiling;
  • any run lacks equivalent watermark and dedupe retention;
  • warmup is included in steady throughput;
  • one implementation disables checkpointing or compression;
  • the sink performs materially different validation work.

Also run a capacity sweep at 25, 50, 75, and 100 percent of target rate. The most informative graph is often latency as load approaches saturation. A system with the highest uncongested throughput but an abrupt collapse under one slow partition may be a poor operational fit.

Finally, publish the harness:

benchmark/
  manifests/run-17.yaml
  generator/
  jobs/flink/
  jobs/spark/
  jobs/beam/
  correctness/oracle.sql
  dashboards/metrics.json
  results/raw/
  results/summary.csv

Performance is not portable. The workload, correctness oracle, configuration, and raw observations should be. That reproducibility turns a benchmark from a leaderboard into an engineering tool for selecting a runtime, finding regressions, and deciding when a different state design or sink is the real bottleneck.