1. 6

Hello. I built a 100% open-source hosting platform for JavaScript microservices, in Javascript. Ask me anything!

The project: http://hook.io

The source code: http://github.com/bigcompany/hook.io

Built with: Node.js, CouchDB, and Github Gist. Node Package Manager modules are fully supported.

Architectural details can be found a bit further down.

Interested, but too busy to read this now?

If you’d like, you can run the following Curl command to opt-in to our mailing list. We’ll periodically send you updates about the project.

curl hook.io?signup=youremail@marak.com

Replace youremail@marak.com with your email address.

What is the purpose of hook.io?

hook.io is an open-source hosting platform for webhooks and microservices. The microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms. hook.io provides an easy way to create, host, and share microservices. Through developing many small re-usable microservices, you can reduce the complexity of your applications while improving stability.

Why or how would I want to use hook.io?

You should want to use hook.io if it can make your life as a developer easier.

The most basic use-case for hook.io is quick and free webhook hosting. You can instantly create a simple hook which parses the incoming parameters of an HTTP request and performs arbitrary actions on it. For instance: Send an SMS message every-time the Hook is requested as a webpage. Since NPM is supported, you can re-use any existing library from the extensive NPM module repository. You can also configure Hooks to be executed on a schedule using a Cron pattern.

At this point, we will take note that Hooks are fully streaming. Inside your Hook source code you have direct access to Node’s http.IncomingMessage and httpServer.ServerResponse request and response streams. This means you can treat the inside of a Hook the exact same way as if it were inside a streaming middleware in a regular node http server. Having direct access to these streams is extremely useful and I am unsure if any other microservice hosting providers currently offer this feature.

More advanced use-cases for hook.io would be replacing individual parts of your application with microservices. Instead of adding a new route or module to your application , you could instead create a Hook responsible for only one unit of functionality and call it using a regular HTTP request from inside your existing application. One specific example could be building a Hook with a custom theme which acts perfectly as a stand-alone sign-up form. This sign-up form can then be loaded server-side in your application using one HTTP get request. It might sound complicated at first, but integrating microservices with your existing application is actually very easy. In the upcoming weeks we’ll work on releasing specific guides for separating application functionalities into microservices.

An even more advanced usage would be building a suite of Hooks and composing them to create new and unique applications! Since every Hook understands Standard In and Standard Out and Hooks can easily call other Hooks from inside each other, there are an endless amount of combinations to be made. This composability enables the foundation for Flow-based Programming without imposing any specific rules for composition. A specific example could be building a Hook ( called “tar” ) responsible for taking in STDIN and streaming out a compressed tar file. Once this Hook is created, you could easily pipe the results of another Hook ( such as an image downloader ) into the “tar” Hook. These Hooks don’t exist yet, but I am certain someone will build them in the near future.

Unix Pipes!

hook.io is very friendly with Unix Pipes. Using STDOUT and STDIN you can connect hook.io to your existing Unix Tool chain. The best way to explain this concept is to review the Curl examples.

Here is one specific example of using hook.io to flip a cat upside-down with cat and curl. You will need to provide your own cat.png

cat cat.png | curl -F 'degrees=180' -F 'image=@-;type=image/png' http://hook.io/Marak/image/rotate > upsidedown-cat.png

The Data!

If you noticed in the last example, hook.io is fully capable of streaming binary data. It also supports streaming file uploads, multipart form uploads, and will assist in parsing all incoming form fields, JSON, and query string data.

Software Architecture

The core software architecture of hook.io is Resource-View-Presenter ( RVP ).

Resources are created using the npm resource module.

View-Presenters are created using the npm view module with regular HTML, CSS, and JavaScript. The same View-Presenter pattern is also used to implement custom theming for Hooks see: hook.io/themes

Important dependencies

mschema - Provides validation through-out the entire stack.

big - Small application framework. Provides website app which hook.io extends.

resource-http - Provides core HTTP server API. Helps in configuring Express with middlewares like Passport

resource-mesh - Provides a distributed event emitter mesh using a star network topography. hook.io primarily uses this module as a monitoring agent to report status back to our monitoring sink.

resource-user - Provides basic user API ( signups / logins / encrypted passwords / password resets / etc )

Server Architecture

There is one front-facing HTTP server and any number of Hook Workers.

The front-facing server is responsible for serving static content, maintaining user session data, and piping requests between the client and Worker.

Workers are responsible for executing user-submitted source code and piping their responses through the front-facing server to the client.

At this point, we will take note that communication between the Hook and client remains streaming throughout the entire architecture. This gives hook.io the ability to perform complex tasks like transcoding large video streams without worrying about clogging up any parts of the system with large memory buffers.

Hook Servers and Hook Workers are immutable and stateless to ensure stability of the platform. They are designed to fail fast and restart fast. mon is used as a process supervisor.

This architecture can theoretically scale to upwards of 10,000 concurrent connections. Realistically, it will probably be closer to 4,000. When the site needs to scale past this, we will create several front-facing servers and load balance incoming HTTP requests to them using DNS.

Hook and User configuration data are stored in a CouchDB database. If the database grows too large, we will split it into several smaller database severs sharded by the first alphabetic letter of every document’s primary key.

Source code for Hooks is currently stored on Github as Github Gists. I’d imagine sometime in the future we will add the option to store and edit source code directly on hook.io itself. The project is open-source, so you could be the first to open up the issue!

Questions? Comments? Feedback?

Let me know! Open-source projects get better with collaboration. Every comment and piece of feedback counts.

Maybe take five minutes to try the platform out? You might like it!

The dependency tree for hook.io is re-used in many applications. Several of these dependencies I maintain myself. If you have feedback or comments about any specific dependency let me know!

  1.