Samuel Williams Sunday, 07 October 2018

Ruby is a language of many revolutions. Rails in particular has re-defined modern web development time and time again. That being said, HTTP/2 support is a blind spot in the modern Ruby web stack, and one which is slowly causing Ruby to fall behind. We present Falcon, a modern asynchronous HTTP/2 capable web server for Ruby. We discuss why HTTP/2 is important, and how to use Falcon.

What is Falcon?

Falcon is a pure Ruby web server that can simplify both the development and deployment. It can handle both HTTP/1 and HTTP/2 traffic, including WebSockets. Rack-compatible web applications can be served directly or as part of a virtual host middleware. This allows Falcon to replace existing heterogenous (e.g. Nginx + Passenger/Puma) environments, and can result in lower latency, higher throughput and simpler deployments.

What is HTTP/2?

HTTP/2, while semantically similar to HTTP/1, is a binary protocol which significantly reduces per-request latency and overhead. Web applications built around the performance characteristics of HTTP/1 no longer perform optimally when served via HTTP/2. This is a problem because estimates suggest that more than 80% of users have web browsers which utilize of HTTP/2 when available.

Domain Sharding

Using multiple domains to increase the maximum number of connections increases operational complexity and per-connection overheads. Managing multiple domains, each with their own SSL certificates, can be time-consuming, and each sub-domain requires independent TLS negotiation, impacting performance. Falcon supports multiple simultaneous HTTP/2 streams which allows web applications to serve all required resources over a single connection. This avoids the need to use domain sharding and increases overall performance.

Asset Bundling

Bundling assets together to minimise the number of requests can actually reduce overall performance. Sprite sheets may download unnecessary images and thus take longer to load than individual images. Small changes to a single JavaScript function might force a combined script bundle to be re-downloaded. Falcon can serve lots of small assets via HTTP/2 efficiently, so pre-processing assets in this way is ultimately unnecessary.

Streaming Everywhere

Buffering request and response bodies increases latency and memory pressure. Large uploads can fail if insufficient disk space is available. Database queries must wait until all rows are retrieved before generating a large JSON response. Falcon supports bi-directional streaming for both HTTP/1 and HTTP/2 and it's easy to stream responses in real time. Taking advantage of this functionality enables lower-latency web applications and reduces memory usage.

Development and Production

Differences in development and production environments can cause unexpected issues which are difficult to catch during automated testing. Web browsers won't load insecure (HTTP) resources when linked from a secure page (HTTPS). Falcon uses HTTP/2 and HTTPS natively in both development and production, so issues like this are more likely to be detected and fixed.

How do I use Falcon?

Falcon is a drop-in server for any Rack-compatible web application with a file. Simply follow the installation and usage instructions. HTTP/2 mandates that web browsers use HTTPS (and ALPN) to negotiate an HTTP/2 connection, which Falcon supports by generating local self-signed certificates.

Falcon also integrates with Guard, Capybara and builds on top of async. WebSockets support is provided by async-websocket which can also be used by itself.

Is it production ready?

Yes, Falcon can be used in production. That being said, given the scope and diversity of the eco-system, there will be issues. Falcon has a large suite of specs, and we hope you will try it and provide feedback so we can continue to make it better.

Business Support

Falcon can be an important part of your business or project. As such, priority business support is available to make every project a success. The first 10 projects to deploy falcon to production get a 50% discount for the first year - just mention this post!


Thank for sharing.

The question is how to integrate falcon with the existing development environment. Which classic gem should be replaced with the async ones (like async-rspec if you use RSpec, async-postgres if you use PostgreSQL, etc.). Some of these gems still have 0.1.* version, can we use it safely? As README of async-postgres says: “This is an experimental drop in wrapper to make Postgres work asynchronously”.

Leave a comment

Please note, comments must be formatted using Markdown. Links can be enclosed in angle brackets, e.g. <>.