Do you need Spark or Flink for that? Streaming on QuestDB
We ran the workloads from an AWS Flink vs Spark Real-time Mode benchmark on a single QuestDB server, with and without Kafka, and no stream processor.
Francisco Morillo, a Solutions Architect at AWS, recently published Spark 4.3 Real-time Mode vs Flink 2.3. Francisco and I worked together at a couple of events back when I was at AWS, so I read it with interest, and it's a careful piece of work: the same six workloads on both engines, the same EKS cluster, a fixed CPU budget, 30-minute runs, two runs per cell, and all the code public.
Looking at the workloads (deduplicate events, count per user in 10-second windows, filter and reshape a stream, join two streams, enrich from a lookup table, find sessions), I kept thinking that most of them are things QuestDB users already do directly in the database. And looking at the numbers, I thought QuestDB could be competitive on them, so I wanted to give it a try.
This is not a "QuestDB is faster than Spark or Flink" post, and QuestDB works with both: there's a QuestDB Flink connector, and Spark can read from and write back to QuestDB. But for several of these workloads you don't need a stream processor at all. You need the data in a database you can query, and if the database can deduplicate, aggregate and join as rows arrive, you've removed a system to run and the extra hop from that system into the database.
On most stateful workloads, QuestDB's slowest 1% of results came in under half a second, against 0.7 to 4.5 seconds for Flink and Spark. Where we could compare CPU, it used less than either engine, except on the stateless workload through Kafka, while also storing every event. Flink and Spark still return a typical result faster, so this is about how much machinery a pipeline needs, not about raw speed.
What the original benchmark measured
The article runs Flink 2.3 and Spark 4.3 in Real-time Mode on EKS (6 ×
m5.2xlarge), reading from Kafka (3 brokers, replication factor 3, 6
partitions). Eight producer pods send about 50,000 events per second of
synthetic clickstream: ts, event_id, user_id, event_type, country,
amount. Each engine gets the same budget, a 1-core coordinator plus two
3-core workers, so 7 cores.
The workloads:
| Workload | What it does |
|---|---|
| Stateless | Filter to purchases and add-to-cart, add tax, uppercase the country |
| S1 | Count, sum and max of amount per user in 10-second windows |
| S2 | Deduplicate on event_id |
| S3 | Sessions per user, closed after a 5-second gap |
| S4 | Enrich each event from a users table (tier, region) |
| S5 | Join orders and payments where the payment arrives within 10 seconds |
"Stateless" describes the computation, not the deployment: each event is handled on its own, with nothing remembered between events, while S1 to S5 keep state across events. Flink and Spark run on the same cluster for all six. For the dedup workload, S2, 10% of events are re-sent up to 3 seconds late as duplicates; the S1, S3 and S4 runs have none.
Latency is out_ts - ts: from the event timestamp to the moment the engine
emits the result. That stops before the result is written anywhere, so the
measurement covers neither storing it nor querying it to power a dashboard or
an API.
The same workloads as tables, views and queries
Every workload maps to a feature QuestDB already has, and none of them needs custom code:
| Workload | Streaming job | QuestDB |
|---|---|---|
| Stateless | Map and filter | Plain view |
| S1 windows | Tumbling window | SAMPLE BY 10s materialized view |
| S2 dedup | Keyed state, TTL | DEDUP SKIP on the table |
| S3 sessions | Session window | Window functions, polled |
| S4 enrichment | Cached lookup join | JOIN with the users table |
| S5 interval join | Keyed states, timers | ASOF JOIN, polled |
The base table does the deduplication. Duplicates carry the same ts and
event_id as the original, so the table keeps the first copy and drops the
rest as they're written:
CREATE TABLE events (ts TIMESTAMP, event_id LONG, user_id LONG,event_type SYMBOL, country SYMBOL, amount DOUBLE) TIMESTAMP(ts) PARTITION BY HOURDEDUP SKIP KEYS(ts, event_id);
The stateless transform is a plain view. It stores nothing: each read filters and reshapes the rows straight from the base table. Querying the last second takes about 6 ms at 100,000 events a second, and about 3 ms at 50,000.
CREATE VIEW events_clean AS (SELECT ts, event_id, user_id, event_type,amount * 1.21 amount_with_tax, upper(country) countryFROM eventsWHERE event_type IN ('purchase', 'add_to_cart') AND amount > 0);
The S1 windows are a materialized view, refreshed incrementally on every commit to the base table:
CREATE MATERIALIZED VIEW events_s1_10s AS (SELECT ts, user_id, count() cnt, sum(amount) sum_amount,max(amount) max_amount, max(ts) max_tsFROM eventsSAMPLE BY 10s) PARTITION BY HOUR;
S3, S4 and S5 are queries that a dashboard or downstream job polls, at whatever interval it needs, for the sessions that just closed, the latest enriched events, or the order and payment pairs just completed.
S5, for example, is the article's interval join. Orders and payments arrive as two streams, and the Flink job emits each order with its payment as soon as both have arrived, if the payment's timestamp is within 10 seconds after the order's. The producer makes that test meaningful: 80% of orders get a payment up to 9.5 seconds later, which must join, 5% get one 11 to 14 seconds later, which must not, and 15% get none.
In QuestDB, S5 is a query:
SELECT /*+ asof_dense(p o) */ p.payment_id, p.ts pay_ts, o.ts order_ts,o.order_id, o.user_id, o.amount order_amount, p.amount pay_amountFROM payments pASOF JOIN orders o ON (order_id) TOLERANCE 10sWHERE p.ts IN '$now-1500T..$now' AND o.ts IS NOT NULL;
The query has two time limits that do different jobs. TOLERANCE 10s is the
article's join rule: for each payment, the
ASOF JOIN finds its order at or before the
payment, and leaves the payment unmatched if the order is more than 10 seconds
older. Unmatched payments come back with a null order, which the last condition
filters out. The $now-1500T..$now filter is only about polling: each poll
reads the payments from the last 1.5 seconds. That's longer than the poll
interval because a payment sent just before a poll can become visible just
after it, and the consumer skips the payment ids it has already seen.
The asof_dense hint matters: a payment's order can be about 250,000 rows
back, and without the hint the default algorithm scans backward that far for
every payment, which takes seconds.
Every run checks the join against the producer's ground truth. In 30-minute runs it returned exactly the expected 11,522,092 pairs at 8,000 orders a second and 38,879,826 at 27,000, and none of the 719,377 and 2,429,070 late payments joined. It returns the same pairs as the equivalent interval join.
Polling is a different model from a stream processor, which pushes each result as it's computed. For a dashboard, an alerting job or an API that reads on demand, polling is enough. For a consumer that needs every result pushed to it, it isn't.
As of the writing of this post, push subscriptions are on the QuestDB public roadmap for QuestDB Enterprise, planned for Q4 2026. An application subscribes to a table or a materialized view over QWP and receives rows as transactions commit, with sequence numbers so it can resume after a reconnect. The S1 view above would then push its results instead of being polled.
Test setup: one m5.2xlarge, 7 cores, with and without Kafka
QuestDB 10.2.0 ran on one m5.2xlarge in eu-west-1, pinned with taskset to 7
of its 8 vCPUs to match the article's 7-core budget, with data on a gp3 volume
and every table and view created before the first row. A separate c7i.2xlarge
ran the producers.
We tested two ingestion paths:
- Direct: a Python producer that ports the article's generator (same rate, with 10% late duplicates in every run except stateless, S1 and S5) writes to QuestDB over QWP in 2,000-row batches.
- Through Kafka: the article's own producer writes to Kafka 4.3.2 on a third m5.2xlarge, and the QuestDB Kafka connector runs on the QuestDB host, inside the same 7 cores. We used one broker with replication factor 1, not three.
Our latency is measured differently from theirs: it runs from the event's ts
to the moment the row is applied and visible to queries, worked out from
QuestDB's own WAL telemetry (sys.telemetry_wal). That covers what the
article measures plus the write to the database.
Every run on both paths was exact: the row count matched the distinct ids and the originals sent, and every view held exactly the rows it should.
Results: latency against Flink and Spark Real-time Mode
All at 50,000 events a second unless noted. Flink and Spark figures are the article's tuned 30-minute runs, averaged over two runs. Its S5 figures come from shorter runs at 8,000 orders a second. We ran every scenario twice, as the article did, and report run 1; the 30-minute S1 and S5 runs and the consumer measurements ran once. S1 and S2 direct ran for 30 minutes, the other table rows for 5.
What each QuestDB row measures:
- Stateless and S2: until the event is visible in the base table.
- S1: until the window is visible in the materialized view.
- S3 and S4: the query time, polled once a second.
- S5: from a payment being sent until a consumer polling every 100 ms receives its pair.
Through Kafka the connector writes rows from several partitions in one transaction, so a row can't be matched to its commit exactly. Those figures are a lower and upper bound per row, and so is the S1 view.
| Workload | Flink | Spark RTM | QuestDB direct | QuestDB + Kafka |
|---|---|---|---|---|
| Stateless, 100k/s | 6.1 | 6.3 | 22.0 | 19-38 |
| S1 windows | 6.9 | 13.4 | 64-155 | 68-153 |
| S2 dedup | 7.0 | 13.1 | 23.5 | 28-29 |
| S3 sessions | 8.3 | falls behind | 274 | 300 |
| S4 enrichment | 6.4 | 6.7 | 37 | 45 |
| S5 join, 8k/s | 7.5 | not in RTM | 89.7 | 97.2 |
Median (p50) latency, ms.
Flink and Spark win the median. Most of QuestDB's is client batching: a 2,000-row batch at 50,000 rows a second takes 40 ms to fill.
| Workload | Flink | Spark RTM | QuestDB direct | QuestDB + Kafka |
|---|---|---|---|---|
| Stateless, 100k/s | 28 | 30 | 35.4 | 45-51 |
| S1 windows | 1,600 | 4,500 | 206-333 | 172-306 |
| S2 dedup | 1,700 | 4,300 | 45.5 | 50-52 |
| S3 sessions | 4,300 | falls behind | 401 | 381 |
| S4 enrichment | 20 | 287 | 87 | 129 |
| S5 join, 8k/s | 690 | not in RTM | 145 | 158 |
Tail (p99) latency, ms.
The tail is where it flips, except on S4. The article's p99s for windows, dedup and sessions come from checkpointing state to S3, and QuestDB's direct 30-minute dedup runs were flat in every 5-minute window.
p99 where QuestDB's figure is ingest latency.
S5 order and payment join at 8k and 27k orders per second
We ran S5 at the article's rate, 8,000 orders a second, with 500-row client batches, so a batch fills in about 35 ms, as at the other rates. With the default 2,000 rows, a batch takes about 135 ms to fill at this rate, and that wait alone would put the payment's median at 73 ms. We also ran it at 27,000 orders a second, 3.4 times the article's rate and about 50,000 events a second, with the usual 2,000-row batches. Spark Real-time Mode doesn't support stream-stream joins, so the article ran Spark's S5 in micro-batch mode, and its Flink figure at 16,000 is a single run.
A consumer polls, so what it sees end to end is the time for the payment to become visible, plus the wait for the next poll, plus the query. We measured consumers polling every 100 ms, each reading the overlapping window shown earlier and timing every pair from the payment being sent to receiving it. Every consumer saw every pair, checked against the database.
| S5 end to end | Median | p99 |
|---|---|---|
| Flink, 8k/s | 7.5 | 690 |
| Spark micro-batch, 8k/s | 3,250 | 5,360 |
| Flink, 16k/s | 33 | 3,500 |
| QuestDB direct, 8k/s | 89.7 | 145 |
| QuestDB + Kafka, 8k/s | 97.2 | 158 |
| QuestDB direct, 27k/s | 140 | 201 |
| QuestDB + Kafka, 27k/s | 159 | 222 |
S5 end-to-end latency, ms.
Polling every 100 ms cost about 0.28 cores of QuestDB CPU at 8,000 orders a second and 0.70 at 27,000, against runs with nothing reading. Each poll costs a roughly fixed amount, most of it the join looking back over up to 10 seconds of orders to find each payment's order, so the cost grows with how often you poll rather than with how much each poll reads.
The 30-minute runs stayed flat as the tables grew: polling every 100 ms, the slowest pair took 165 ms at 8,000 orders a second and 277 ms at 27,000.
Flink pushes each pair as soon as it's joined, so it wins the median. A consumer polling every 100 ms beats its tail, and QuestDB also leaves the result stored and queryable, with no separate engine to run.
Resources: CPU and memory for the same work
Each engine's CPU and memory for the same workloads, at 50,000 events a second unless noted:
| Workload | Flink | Spark RTM | QuestDB direct | QuestDB + Kafka |
|---|---|---|---|---|
| Stateless, 100k/s | 1.1, 5.5 GiB | 1.7, 8.1 GiB | 0.65, 0.85 GiB | 1.72, 1.90 GiB |
| S1 windows only | 3.5, 7.1 GiB | 4.0, 9.5 GiB | 1.98, 0.94 GiB | 2.81, 1.85 GiB |
| S2 dedup only | 3.7, 6.2 GiB | 3.6, 9.2 GiB | 0.40, ~1.1 GiB | 0.74, ~1.7 GiB |
| All, 30 min | 2.31, 1.30 GiB | 3.12, 1.91 GiB |
Mean cores, then mean memory.
Dedup costs QuestDB a tenth of what it costs either engine, because it happens as part of the write. The S1 view, including the writes it's built from, used less CPU than either engine, and so did the stateless workload direct, while also storing every event. Through Kafka the connector adds about 0.8 to 0.9 cores at 100,000 events a second, level with Spark. Neither side counts the Kafka brokers, and the last row also ran a materialized copy of the stateless transform, so it overstates what this setup needs.
The memory columns aren't directly comparable: Flink and Spark report the cgroup working set, QuestDB its process RSS, which leaves out the memory-mapped data it keeps in the page cache, so the gap is real but smaller than it looks.
Surviving restarts without losing a row, with or without Kafka
The article also tests recovery: it kills a worker mid-run on the S1 windows,
a Flink TaskManager or a Spark executor, and measures how long results take to
get back on time. We ran the same test on QuestDB, on both paths. A single
server has no worker to lose, so we killed the whole process with kill -9
mid-run and restarted it immediately, as a supervisor such as systemd or
Kubernetes would. Every row written during the outage was queryable 3.0 seconds
after the kill on the direct path, and 3.4 seconds through Kafka.
Recovered means what the article defines: at least 90% of the input rate with mean latency under 1 second, for 5 seconds in a row. Neither engine lost or double-counted a window, although each kill re-emitted about 2.3 million (Flink) or 3.2 million (Spark) records for the sink to absorb.
| Setup | Killed | Recovered | Lost | Duplicates in results |
|---|---|---|---|---|
| Flink | 1 worker | 62-70 s | 0 | 0 |
| Spark RTM | 1 worker | Not before the test ended | 0 | 0 |
| QuestDB direct | Server | 3.2 s | 0 | 0 |
| QuestDB + Kafka | Server | 4.2 s | 0 | 0 |
Time to recover after the kill.
Through Kafka, QuestDB answered queries again at 2.9 s and every row was back within 100 ms at 5.2 s. There the broker holds the events while QuestDB is down. On the direct path the client does it: store-and-forward writes outgoing batches to local disk until the server acknowledges them, then reconnects and resends on its own. With dedup on the table, a resend can't create a duplicate. On QuestDB Enterprise the same applies across a failover to a replica.
Keeping producers going through a restart, a network drop or an upgrade is the reason many teams put Kafka in front of a database. If that's its only job, the client already does it, and Kafka costs about 5 ms of latency plus 0.3 to 0.5 cores for the connector at 50,000 events a second. Kafka is still the right tool when several consumers read the same stream, when you need to replay days of history into a new system, or when it's already the backbone of your platform.
Scaling from 50k to 100k events per second and back
The article doubles the input rate for 100 seconds mid-run, to see whether an engine sized for 50k can absorb a spike. Flink needs to be sized for the peak or rescaled by its autoscaler, and Spark Real-time Mode has no autoscaling.
QuestDB doesn't rescale anything. At the peak, the S1 view's p99 rose to 0.42-0.80 s direct and 0.34-0.63 s through Kafka, then came back down when the rate dropped. CPU went from 2.3-2.4 to 3.6-3.7 cores direct and back.
Three config changes from the defaults
The article tuned Flink and Spark, from checkpoint intervals to buffer timeouts,
and reports its tuned runs. QuestDB needed three changes in server.conf, plus
two client settings: 500-row batches for S5 at 8,000 orders a second, and
reconnect_max_backoff_millis=500 on the producer and the connector, which
caps the client's reconnect backoff. The default grows to 5 seconds, so a
client can still be waiting seconds after the server is back.
# Merge-append partitions, opt-in since 10.1cairo.o3.partition.merge.append.enabled=true# Dedicated pools sized for 7 coresshared.network.worker.count=2shared.write.worker.count=2shared.query.worker.count=3wal.apply.worker.count=2mat.view.refresh.worker.count=2# Idle workers nap after 100 loops and sleep after 1000 (defaults 7000 / 10000)shared.worker.nap.threshold=100shared.worker.sleep.threshold=1000wal.apply.worker.nap.threshold=100wal.apply.worker.sleep.threshold=1000mat.view.refresh.worker.nap.threshold=100mat.view.refresh.worker.sleep.threshold=1000
- Merge-append partitions are built for this pattern: late rows and duplicates arriving in a narrow recent range. Without them, every commit carried out-of-order rows, the cost of applying one grew with the open hour partition, and a materialized view's p99 reached 2.3 seconds within five minutes, at 6.8 of 7 cores.
- Dedicated pools keep queries from slowing ingestion. REST, QWP and anything else over HTTP share the network pool, so give it enough workers for the parallel requests you expect.
- The idle thresholds took CPU from 4.53 to 1.40 cores in a 2-minute test with the same latency. With the defaults, idle workers spin between commits, so CPU follows the commit rate more than the row rate.
If your data arrives in order and without duplicates, the first change doesn't matter.
Where a stream processor still wins
- Median latency. Flink and Spark emit in 6 to 13 ms. QuestDB needs a batch to fill before a row is visible.
- Pushing results. S3, S4 and S5 run here as queries that a client polls. If a downstream system needs each result pushed to it as it happens, a stream processor does that and QuestDB doesn't yet.
- Stateless transforms through Kafka at high rates, if you never need to store or query the events: the connector puts that path level with Spark on CPU, and above Flink.
- Joining data that won't live in the database: CDC from an operational database, a partner's topic, or any source you don't want to store. A stream processor joins them in flight; QuestDB joins what it has ingested.
- Logic that isn't SQL: complex event processing, custom state machines, calls to external services per event, fan-out to many sinks.
If what you do with the stream ends up in a database anyway, deduplicated, windowed and joined so people and services can query it, a database that does those things on ingest can replace the stream processor, and often Kafka with it.
When you do need one, both Flink and Spark can write their results to QuestDB.
Reproduce it
Everything is in
questdb/blog-examples:
the producers, table and view definitions, the latency scripts that read
sys.telemetry_wal, the Kafka connector setup, and the scenario runner, along
with the exact AWS setup. The Flink and Spark side, including the raw results
we compared against, is in Francisco's
fmorillo7694/spark-rtm-vs-flink.
Your numbers will differ with hardware, network and batch size.
Thanks to Francisco for publishing a benchmark this easy to rerun.