krisleech

krisleech

A strategy for consuming Change Data Capture events

I’m using Broadway to consume Change Data Capture events from Kafka.

As such we need to process the events in the order they arrive. Each entity (let’s say “posts” and “comments”) has Change Data Capture events published to a different Kafka topic. The message key is set to the UUID of the entity.

Because broadway alway ack’s a Kafka message even if it is marked as failed or an exception occurs we have wrapped the handling function in a infinite retry, so it captures any error and recursively calls the handler again with the same message. If it’s an transient failure it will eventually be successful otherwise we need to deploy a fix.

We are batching based on the message topic, mapping the topic directly to a batch, approximately: Message.put_batcher(message, String.to_atom(message.metadata.topic))

My question is around concurrency, we need to set the concurrency for each batcher to 1 to ensure the messages are processed serially, in order.

Would we then be able to set the producer concurrency higher as the batchers can be processed in parallel (since each batcher is a different topic, i.e. relates to a different entity type).

    Broadway.start_link(__MODULE__,
      name: __MODULE__,
      producer: [
        module: {producer_module(), producer_opts()},
        concurrency: 2 # number of batchers (aka topics)
      ],
      processors: [
        default: [
          concurrency: 10
        ]
      ],
      batchers: [
        cdc_posts: [
          batch_size: 100,
          batch_timeout: 200,
          concurrency: 1
        ],
        cdc_comments: [
          batch_size: 100,
          batch_timeout: 200,
          concurrency: 1
        ]
      ]
    )

By having a concurrency of 1 per batcher, but 2 for the producer, it means that the events in each topic/batch will be processed sequentially, but the batchers will not block each other, for example if a message in one batcher can’t be processed it will retry and not block the other batchers?

I’m not sure how the processors concurrency relates…

Many thanks!

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New

We're in Beta

About us Mission Statement