afterclick
728 × 90

Engineering

Pushing Python: lessons from a high-throughput distributed system

From ten million events a minute to ten million events a second. That was the jump TellApart reported for Taba, its distributed event aggregation service, roughly two years after first releasing it as open source. Getting there took a rewrite of the core server, and the result shipped publicly as Taba v0.3. One of the engineers behind it presented the lessons at PyCon 2014 in Montreal, and the point of the talk was that high-throughput Python was possible, if you respected the language’s limits.

The original Taba design folded events into compact State objects behind stateless Python servers with Redis underneath. Version 0.3 kept that shape and changed nearly everything inside it.

What Taba v0.3 added

Throughput was the headline, but the release also carried a list of features users had asked for. Clusters discovered and balanced themselves. Redis Sentinel was supported for database discovery and automatic failover. Queries could use regular expressions over Tab names and client IDs. A query cache cut the response time of the most common large queries from several minutes to a couple of seconds. Type Handlers became pluggable, and “super-aggregates” could combine any Tabs of the same type. Taba also moved to standard Python packaging and PyPI.

Two further decisions mattered as much as the code. TellApart moved its own internal deployment onto the public version and committed to doing all new development in the public repository, so outside users would get every later improvement. And it released a Java client library, which meant JVM services could report into Taba too.

Four lessons for high-throughput Python

The PyCon talk and the accompanying post boiled the rewrite down to four lessons. Each one still applies, and each says something about where Python’s limits really are.

The data model sets the ceiling

A small change in how States were combined into query responses made aggressive caching possible, and that one change cut response times by several orders of magnitude. No amount of profiling or C extensions would have bought that. The lesson generalises: in a high-throughput Python system, the biggest wins come from choosing a representation that lets you skip work, not from doing the same work faster.

Put state in one hardened place

Consistent, durable state is a hard problem, so Taba did not solve it. A small central cluster of Redis instances held all state as a hardened sub-service, and the server workers kept nothing. Workers could join or leave the cluster freely, which made the system resistant to failures and simple to scale. This is now standard practice, but in 2014 plenty of Python services still kept important data in process memory and paid for it on every restart.

Generators and greenlets compose well

Taba used generators together with gevent greenlets over and over to build just-in-time processing pipelines. A generator produces items only when the consumer asks for one; a greenlet lets many such pipelines run concurrently while waiting on the network. Combined, they give you streaming processing with bounded memory and very little coordination code.

A rough modern equivalent with asyncio looks like this:

import asyncio

async def read_batches(queue):
    while True:
        batch = await queue.get()
        if batch is None:
            return
        yield batch

async def fold(queue, state):
    async for batch in read_batches(queue):
        for counter, value in batch:
            state[counter] = state.get(counter, 0) + value

The shape is the same: a lazy producer, a consumer that pulls one batch at a time, and no list of every in-flight item held anywhere.

CPython fragments memory under heavy churn

The least obvious lesson was about memory. CPython struggles to manage memory in long-running processes that push a high volume of data through, especially when large and small objects are mixed. The heap fragments, and resident memory climbs even though live data does not. Taba fought this in three ways: generators to limit how many objects were in flight, manual allocation of critical memory blocks to control where they lived and when they were freed, and avoiding long-lived objects that cause the heap to ratchet upward.

That last pattern deserves a plain explanation. If a long-lived object lands in a memory arena full of short-lived ones, the arena can never be returned to the operating system, even after everything around it is freed. Do that often enough and a process ends up holding several times the memory its live data needs.

Would you still build it in Python?

That is the question the talk invited, and the honest answer in 2026 is: sometimes. Python itself has moved. CPython 3.11 and later releases brought large interpreter speed-ups, free-threaded builds without the global interpreter lock arrived experimentally in 3.13, and asyncio has replaced gevent for most new network code. Tools like memray make fragmentation problems visible in minutes instead of days.

For an event aggregation tier like Taba’s, though, most teams would not write the hot path in Python at all. They would use an OpenTelemetry Collector, Vector or a Kafka-plus-Flink pipeline for ingestion, and keep Python for the query layer, the Handlers and the glue. If you do need custom high-throughput Python, Taba’s four lessons are still the checklist: model the data so work can be skipped, keep state out of the workers, stream with generators, and watch the heap over days, not minutes.

There is a side note worth keeping. TellApart also open-sourced a gevent request profiler for finding code that blocked the event loop, a problem that has simply changed names in the asyncio era. The broader question of how much to compute ahead of time and how much on demand is the subject of the piece on fast data and the Lambda Architecture, and it is the question Taba’s cache quietly answered.

Questions readers ask

What changed in Taba v0.3 besides throughput?

Clusters discovered and balanced themselves, Redis Sentinel handled database discovery and automatic failover, and queries could use regular expressions over Tab names and client IDs. A query cache cut the most common large queries from several minutes to a couple of seconds. Type Handlers became pluggable, super-aggregates combined Tabs of the same type, packaging moved to PyPI, and a Java client let JVM services report in.

Why does CPython memory keep growing when live data stays the same?

In long-running processes that move a lot of data, especially mixing large and small objects, the heap fragments. If a long-lived object lands in a memory arena full of short-lived ones, that arena cannot be returned to the operating system even after its neighbours are freed. Taba countered this with generators to limit objects in flight, manual allocation of critical blocks, and avoiding long-lived objects that ratchet the heap upward.

Would a team write a service like Taba in Python today?

Sometimes, but rarely the hot path. CPython 3.11 and later brought large speed-ups, free-threaded builds arrived experimentally in 3.13, and asyncio has replaced gevent for most new network code. For ingestion, most teams would use an OpenTelemetry Collector, Vector or Kafka with Flink, keeping Python for the query layer, Handlers and glue. Custom high-throughput Python still follows Taba's checklist: skippable work, stateless workers, generators and a watched heap.

What did TellApart change about how it maintained Taba after v0.3?

Two decisions went beyond code. TellApart moved its own internal deployment onto the public release and committed to doing all new development in the public repository, so outside users would receive every later improvement. The company also open-sourced a gevent request profiler for finding code that blocked the event loop, a problem that still exists under a different name now that asyncio has replaced gevent for most new network code.