pnezis

pnezis

I am using broadway lately (which by the way is a pleasure to work with) for some data pipelines and I am wondering if the approaches I have taken are the optimal ones.

Context

The basic workflow is:

  • Read messages from a set of kafka topics
  • Process the raw messages and extract a set of valid json documents. Some incoming may be invalid so we need to ignore them.
  • Store the processed data.

How to ignore/skip raw messages.

Incoming data are processed in a process_data function which returns the status of the processing and the transformed data. The returned statuses can be :ok, :skip or :error. Currently I am handling messages as following:

def handle_message(_, %Message{data: data} = message, _) do
    case process_data(data) do
      {:ok, data} -> 
            Message.update_data(message, fn _ -> data end)
            |> Message.put_batch_key(data.type)
            |> Message.put_batcher(:default)

      {:skip, reason} ->
          Message.failed(message, reason)

      {:error, reason} ->
          Message.failed(message, reason) 
    end
end

Question 1

Should I mark the messages as failed directly or should I add them to the batcher and ignore them in the handle_batch function?

Multiple batchers

Assume that I want to do more than one operation on the successfully processed messages, e.g. store them in a database and store them to s3. broadway does not support propagating the same message to different batchers for good reasons. I see two options here:

  • Use a single batcher and do all the batch processing (e.g. store mesages both to the database and s3). The drawback of this approach is that I cannot have different batch_size and batch_timeout options.
  • Create a pipeline for each batcher. The drawback of this approach is that the same raw messages will be processed multiple times.

Question 2

Is there any alternative method? What do you think is the best approach for that use case?

Multiple extracted messages for each incoming message

Each incoming kafka message may contain multiple sub-messages. For example a raw message can be:

[A1, A2, B1, C1, B2, A3]

where A,B, C are the different message types. I would like to do something like:

extracted_messages
|> Enum.map(fn x -> Message.put_batch_key(x, x.type) end)
|> Enum.map(&Message.put_batcher(&1, :default))

The problem here is that handle_message must return exactly one message, so I cannot split a single incoming messages to multiple processed messages, each of which should have a different batch key or potentially a different batcher.

Question 3

The approach I am currently following is to send each of these sub-messages to another kakfa topic and handle them with a secodary pipeline. Is there any better solution? Could this be achieved in a single pipeline?

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews