Netflix OSS: Batch Requests with Ruby on Rails and Ember.js

by Srinivas Raghunathan, Shishir Kakaraddi, and James Menera

We are pleased to announce the open source release of three Batch Request related libraries.

Libraries:

Ember Batch Request (Ember JS Add on)

Batch Request API (Rails Middleware)

Batch Request Client (Ruby Client)

Introduction

Batching allows you to pass several operations in a single HTTP request. How do we make a Batch request from Ember UI and process it on a Rails backend? Ember Batch Request and Batch Request API to the rescue. A JSON array of HTTP requests are created on the UI using an Ember add-on and then processed sequentially or in parallel on the backend API through the Rails Middleware.

Why

A batched approach is quite useful for making a high number of creates/updates/deletes in a transaction, owing to a single network request. When it comes to building performant applications, an efficient database query is the key. By using the option to process in parallel, transactions come in place, giving us atomicity and efficiency. These two libraries help you get there without much effort.

Usage

On the Rails API, once the batch_request_api gem is added, the application gets the middleware to handle the incoming batch request from the Ember UI.

On the Ember UI, the ember-batch-request add on gives you 3 new store methods to make batch requests.

Create:

this.store.batchCreate(arrayOfObjects).then((response) => { });

Update:

this.store.batchUpdate(arrayOfObjects).then((response) => { });

Delete:

this.store.batchDelete(arrayOfObjects).then((response) => { });

As a bonus, we have released the Batch Request Client to help you make batch requests from another Rails application if you are not using Ember.js.

Batch Request Payload:

{
"requests": [
{
"method": "POST",
"url": "/api/v1/movies",
"body": { }, { }
}
]
}

Batch Request Response:

[
{"status"=>200, "headers"=>{}, "response"=>{}},
{"status"=>200, "headers"=>{}, "response"=>{}}
]

Dependency

Currently works with Rails and Ember Applications using JSON API spec.

Future Work

We plan to make the libraries JSON API spec agnostic and add more features. We welcome suggestions, improvements, corrections and additional tests.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.