block by joyrexus 7643968

Your API does REST, but can it SLEEP?

SLEEP (Syncable Lightweight Event Emitting Persistence) is an emerging standard for distributed data sync using HTTP and JSON. A generalized version of CouchDB’s much lauded built-in replication, SLEEP extends the REST architecture to define a way in which databases can offer syncable JSON APIs that foster open data innovation by allowing developers to replicate entire databases over the net.


SLEEP comes from the Apache CouchDB project which is now widely known for it’s multi-master streaming HTTP + JSON replication. This is possible in part because of the CouchDB _changes feed, which is a particular API that lets you see if there have been any changes made to the database since last time you synchronized. CouchDB can efficiently implement the _changes feed because of one subtle difference between it and most other databases: it stores a history of all changes that happen to the database, including deletes.

If you synchronize data from a remote source and then the remote source deletes a bunch of data, how do you find out what to sync when you want to synchronize again? The simplest solution is to keep enough history stored in your database so that you can produce an append-only transaction log of all data operations that remote sync clients can use to check for new changes.

In essence this append only _changes feed is what SLEEP describes. All you have to do to make your API SLEEPy is a) store CRUD operations (especially deletes) and b) expose your changes feed as JSON over HTTP. There are a number of middleware plugins being developed for major MVC frameworks (Rails, Django and Drupal) to make SLEEP a plug and play enhancement.

Further Reading