Pusher is built to handle scale — every month we deliver 160 billion messages to 6.5 billion devices. Developers use Pusher to build scalable apps with millions of users, so they need to be able to push different events at the same time. We wanted to make this easy, so you can now publish a \[…\]
Pusher is built to handle scale — every month we deliver 160 billion messages to 6.5 billion devices. Developers use Pusher to build scalable apps with millions of users, so they need to be able to push different events at the same time. We wanted to make this easy, so you can now publish a batch of events.
Pusher client libraries now allow you to send multiple distinct events in a single HTTP call using the Batch Events API method.
Let’s say you have a message queue and you want to publish these messages more efficiently, you can batch events into one call.
Usually messages are published on a one-to-one with events, but if your app has logic to publish many different messages to channels based on one event, you can use publish them all at once with a batch call.
All of our multi-tenant clusters accept up to 10 events per request. If you need to send larger batches, we can offer this if you are on a dedicated cluster where other customers won’t get impacted by the higher load. If you’re interested in this, get in touch with us.
Every HTTP call contains around 400 bytes in the request header. Depending on the size of the event this can represent up to a 10x overhead per event. But batching events into one call solves this by making fewer calls.
Batching is particularly well suited if the events are fetched from a message queue or generated in the process itself. Here is an example in ruby where “events” is an unbounded list of events.
1events.each do |(channel, event_name, data)| 2 pusher.trigger(channel, event_name, data) 3end
1events.each_slice(10) do |events| 2 pusher.trigger_batch(events) 3end
It’s important to note that this is for multiple unique events, if you’re looking to send the same event to multiple channels use the POST event instead.
All of our official client libraries have been updated, as well as the documentation for batch events. The feature is available in the following versions or newer:
Any other existing client libraries can be updated by following the spec (or ask support if you need the support for another language).
We’re always thrilled to see how our tools help developers solve problems. Give batch events a spin and then send us your feedback.