Skip to content
indolering edited this page Nov 7, 2014 · 1 revision

Speech.js has made several architectural decisions that maximize scalability and speed while reducing maintenance effort. This article attempts to document these choices.

Scaling

Speech.js has excellent scaling characteristics thanks to the following architectural choices:

  1. Static JS frontend.
  2. HTTP/CouchDB DNS backend API.
  3. Free caching from CloudFlare.
  4. (eventually) Peer-to-Peer DNS.

Speech.js compiles into a single, precompressed HTML file and the HTTP server simply returns that single HTTP file no matter what the request is. CouchDB is also very performant, taking advantage of Scala for parallelism and map/reduce processing of data. The key to the performance and scalability of Speech.js and CouchDB is that they utilize plain HTTPS, meaning that we take advantage of every HTTP cache on the network, from our data center to CloudFlare to your ISP. It also means that the entire stack can take advantage of CloudFlare's caching edge servers, DDoS mitigation, and web firewall.

What's really cool is that there is already native P2P support for PouchDB using WebRTC. After we add support for signing DNS records (remember, we are still in the "developer preview" stage) we can tap into this P2P network and scale up operations very cheaply.

#Speed The ideal time to loading the .bit site is below <100 ms, the rough minimum perceivable passage of time. Google is able to load their homepage in that amount of time using a bunch of tricks, but we aren't ready for such extremes just yet. Because of the choice of a static JS app and HTTP for the database protocol, Speech.js needs to perform lot of upfront work when first connecting with the client. Thankfully, we should still be able to perform the initial DNS resolution and begin fetching the .bit site in less than second on a cold start and close to 100 milliseconds with a warm cache.

The primary "optimization" we currently undertake is to inline all CSS and JS (including PouchDB) into a highly compressed HTML file. While we currently use the minified version of PouchDB, Speech.js itself is not minified. Instead, we precompress the entire script to achieve maximum compression and the zipped output only differs by ~3KB. That overhead amounts to a 25ms performance penalty, one we are willing to accept for now.

Eventually, we will break the site into three parts, one for the initial DNS lookup, another for handling Babel.js requests, and a third for DNS syncing. The initial loader will check for a DNS record in the local cache and (on cache misses) fetch the latest record from the DNS API. After the .bit site begins to load, Speech.js will lazy load the rest of the necessary JS, spawn a webworker, and sync the DNS database in the background.

Clone this wiki locally