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

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
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
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New

We're in Beta

About us Mission Statement