0.0.3 • Published 4 years ago

bytesocket v0.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

Bytesocket

Universal Programmable Bitcoin Push Notifications Service

Try here: https://infinite.bitsocket.org/

bytesocket

Features

Bytesocket is a next generation implementation of Bitsocket, redesigned from scratch. Highlights:

1. Scalable

The old version triggered an event for every single incoming transaction for each listener client.

Scaling Bitsocket using this approach is impossible, as the events to process grows along with the global transaction volume.

Bytesocket does it differently. It uses a hybrid approach of both polling and push technologies.

  • On the server side it polls Planaria for a set of transactions that match the bitquery filter, once every 1 second (configurable).
  • On the client side it uses SSE to provide realtime experience.

Aside from scalability, there are many benefits to adopting this approach, which will be explained below.

2. Reliable

With the new architecture, you can NEVER miss an event. In the old version, if your bitsocket client went offline and came back up, you would have missed all the events that happened during the off-time.

Bytesocket takes advantage of the Last-Event-Id feature built into Server Sent Events.

Note that this is only possible because of the new architecture which uses the Planaria database instead of trying to process all incoming events directly.

3. Consistent

The old version of Bitsocket used a library called Mingo to filter transactions in realtime.

The problem was, Mingo was an emulation of MongoDB query using JavaScript, which means it wasn't directly using the database. It directly looked at an incoming transaction and used the query to filter.

This sometimes resulted in inconsistent results, meaning the same Bitquery which returned certain data set from Planaria wouldn't be able to pick up on realtime transactions. This became more severe with the BOB schema, which consisted of a more complex data structure.

Bytesocket solves this problem because it is directly powered by the underlying Planaria database. It is 100% consistent with the result you would get from querying the Planaria node.

4. Expressive

Also because the old Bitsocket was using the direct filtering approach instead of using the database, this limited Bitsocket to a limited set of query types.

For example, you could filter using find but could not apply project operations.

With Bytesocket, this is no longer the case because the push notifications are directly generated from the Planaria database.

5. Segmentation

Because we get rid of the restriction that all transactions must be processed in realtime for every existing filter, and instead create a buffered approach where push notifications are generated from the database, we can potentially customize the push notification frequency for every client.

For example, certain applications only want to get a notification once every 24 hours. And certain applications only want to get a notification once every 10 minutes. And certain applications which are much more time sensitive, may want to get push notifications as quickly as 0.1 second.

With the new architecture, Bytesocket is able to serve all these different segments in a customized manner. And this means the socket API can also provide multiple pricing model for each customer segment. Those who want more immediate notifications may want to pay more. Those who are not as time sensitive, can pay less.

NOTE: This is not implemented yet in the current version. But can be easily added, thanks to the new architecture**

Usage

Step 1. Install Chronos Planaria

You need to have a Chronos planaria up and running.

Step 2. Clone and run Bytesocket

Then, clone this repository and run:

npm install
node index

Important: If you're using nginx, remember to update the nginx settings to something like this in order to minimize disconnections:

server {
  ...
  location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
  }
  ...
}

Step 3. Customize Whitelist

In a browser, by default Bytesocket only allows access to its host as well as whitelisted URLs, which can be configured through the whitelist.json file.

On server side, it allows full access. (TODO: add auth for server-side bytesocket subscriptions)