cabol

cabol

Hello,

I am happy to announce Tidefall.

Tidefall is an ETS buffer for high-throughput writes and batch processing. You write data into it as fast as you must. The buffer holds the data in partitioned ETS tables. At a fixed interval, it sends each batch to a processor function that you supply.

There are two buffer types. Tidefall.Queue keeps the insertion order. Tidefall.HashMap collapses writes that have the same key, so only the most recent value stays.

Tidefall gives at-most-once delivery. If your processor crashes, the buffer loses that batch. This is a deliberate choice, not a gap. On a normal shutdown, the partition traps exits and drains what remains. If you need a stronger guarantee, the processor can take ownership of the table and hand it to a durable handler.

Some of you know partitioned_buffer. I wrote it with the team at Appcues, and Appcues released it under the MIT license.

We ran it in production for months. It buffered writes to a message broker, and it collapsed duplicate events by key before expensive downstream work. Tidefall keeps that same engine, so the core is not new code.

Tidefall is a fork of that library. It is not a replacement. partitioned_buffer is alive, and Appcues maintains it. Tidefall has a different scope and a different roadmap.

The story behind the fork

I wrote a blog post about it. It is the best next read if this library interests you.

The post covers the three use cases that shaped the design. Each one added a capability: batch writes to a message broker, then coalescing by key, then version-aware updates.

Blog Post: Buffering High-Throughput Writes in Elixir: Introducing Tidefall

Thank you to the Appcues team for the original library, and to the OpenTelemetry batch processor for the initial inspiration.

Feedback and issues are welcome.

Links:

Showing Posts 1 to 4

krasenyp

krasenyp

Congrats on the release. I have a couple of questions.

  • Why is this library an application? Couldn’t it be just a supervisor which the user adds to their supervision tree?
  • Can the library be integrated with Broadway somehow?
cabol

cabol OP

Thanks! And both good questions.

Couldn’t it be just a supervisor which the user adds to their supervision tree?

First, an important point. The application does not own your buffers. Your buffers still live in your supervision tree. You add {MyApp.EventQueue, processor: &MyApp.Sink.export/1} to your children, and you control the restart strategy.

The rule I used is simple. If a thing belongs to one buffer, it lives in that buffer’s tree. If all buffers share a thing, it lives in the application. The partitions and their ETS tables belong to one buffer, so they stay in the buffer tree. Two things are shared, so they moved to the application.

The first is Tidefall.Metadata. It is one ETS table. It holds the current table pointer for each partition. Every write reads this pointer to find the active table. Every processing tick rewrites it when the partition swaps the two tables. It is a GenServer only because a process must own the table. No call goes through it. A call would make one process the bottleneck for every write in the system.

This is also why it is not :persistent_term. That was the first design. :persistent_term.put/2 copies the whole store on every write, and this pointer changes on every tick, for every partition, in every buffer. ETS gives fast reads and fast writes, with no copy.

The second is Tidefall.Registry. Each partition registers under its buffer name. The buffer uses it to find all of its partitions.

Now the real question. Why not put these two in the buffer supervision tree? Because then every buffer gets its own copy, and the cost is not small. The Registry uses one partition per scheduler by default. On a 16-core machine, that is 16 partitions, and each partition has its own table and its own process. Five buffers would create 80 registry partitions, only to support lookups. One shared Registry pays that cost one time. You also get better concurrency, because the partitions follow the schedulers, not the buffers.

The metadata table has the same shape. Each buffer adds only a few entries. An ETS lookup costs the same with 10 keys or with 10,000 keys. So one table per buffer adds tables, but it adds no speed.

The result is one small supervisor with two children for the whole VM. Ecto, Nebulex, and Phoenix.PubSub use the same approach. Shared infrastructure lives in the application, and your own components live in your tree.

If the Registry is still too large for your system, you can tune it with config :tidefall, registry_partitions: 2.

Can the library be integrated with Broadway somehow?

Yes, you can. But let me be honest about one thing first. If you only need to group messages into batches, use Broadway’s batchers. Do not add Tidefall. Broadway already does that job well. Tidefall solves a different problem. A batcher groups messages. Tidefall collapses them.

Here is the difference in practice. Your topic carries one million events, but they cover only one thousand entities. With a batcher, a batch of 1000 messages still holds 1000 messages. If 900 of them repeat the same key, you receive all 900. You must collapse them yourself inside handle_batch/4, and you hold all of them in memory until the batch closes.

With Tidefall.HashMap, the write collapses the duplicate immediately. The buffer keeps one row per key. One million events become one thousand ETS rows, not one million message structs. Your processor then receives one entry per key.

So the reason to put Tidefall downstream is the memory shape and the write semantics. It is not the batching.

You also get two things a batcher does not give you. The first is version-aware writes. put_newer/4 replaces a value only when the new version is higher, so a late event does not overwrite fresher data. The second is a hit counter. Each entry reports how many times its key was updated while it waited in the buffer.

There is one more difference. A batcher only sees the messages inside its pipeline. A Tidefall buffer accepts writes from any process. A Broadway pipeline and a Phoenix controller can write to the same buffer, and their writes coalesce together.

Now the caveat, because it matters. This moves the acknowledgement boundary. Broadway acks the message as soon as you write it into the buffer. Tidefall gives at most once delivery. If the processor crashes, that batch is lost. You turn end-to-end at least once into at most once after that point. That is fine for analytics, for state sync, and for cache updates. It is not fine when you need the source to send the data again after a failure.

If you need durability there, use processing_batch_size: :table. Your processor receives the whole table, and it can give the table away to a durable handler before it does any risky work.

The other direction, Tidefall in front of Broadway, is possible but awkward. Broadway producers are demand-driven, so you would write a custom producer around the buffer. I would only do that for a specific reason.

The blog post compares the two in more detail: https://medium.com/erlang-battleground/buffering-high-throughput-writes-in-elixir-introducing-tidefall-87e4d9bd6079

I hope that answers both questions. Please tell me if anything is still unclear, or if you want more detail on either one. Thanks!

tiagodavi

tiagodavi

Thanks for sharing it. I was looking for something like this to solve specific problems:

Triggering tasks to write to the database on every single authenticated API. These requests poses a significant performance and reliability risk. Under heavy load, this will rapidly exhaust the Ecto database connection pool.

I was thinking to create something like UsageTracker that accumulates this in batches and eventually dispatches the batch to the database and this library looks like a good fit for that.

cabol

cabol OP

Thanks :folded_hands:

Triggering tasks to write to the database on every single authenticated API. These requests poses a significant performance and reliability risk. Under heavy load, this will rapidly exhaust the Ecto database connection pool.

I was thinking to create something like UsageTracker that accumulates this in batches and eventually dispatches the batch to the database and this library looks like a good fit for that.

Yeah, that is a perfect use case for Tidefall :ok_hand:!!

— All posts loaded —

Where Next? Top

Trending in Announcing Top

wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
handnot2
Samly can be used to enable SAML 2.0 Single Sign On in a Plug/Phoenix application. This library uses Erlang esaml to provide plug enabl...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
restlessronin
The repo is at GitHub - cyberchitta/openai_ex: Community maintained Elixir library for OpenAI API · GitHub. Docs are at OpenaiEx User Gu...
152 11030 135
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mudasobwa
I am seeing a lot of aplications of Argumentum ad Vericundiam in software discussions. They do link some piece of writing and point us to...
New
bartblast
Hey folks, I just published a post about Hologram’s funding and where the project goes next - the short version: Curiosum as Main Spons...
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
Herve37
We’re evaluating API mocking tools for OpenAPI-based projects and would love to hear what other teams are using. We’re particularly inte...
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews