Use Dynamic Batching
Learn about a batching technique called dynamic batching.
Dynamic batching
Static batching is great when we know how to group our messages in advance. However, often messages contain dynamic data, which means that static batching is not going to work. Thankfully, Broadway
gives us the option to define batches at runtime using :batch_key
. This is also called dynamic batching.
To use dynamic batching, we set :batch_key
on the message using Broadway.Message.put_batch_key/2
in our handle_message/3
callback. The batch key then partitions the data within each batch for each batcher group.
We can demonstrate how dynamic batching works by improving our email notifications. Right now, if a user makes multiple bookings, they get ...