Blot
Contents

Engineering

When I started working on Blot, I did not know how to program. I did less research than I ought to have done. I wasted time creating tools that others had already made.

Infrastructure

  • We avoid using tools that have been around for less than a decade.
  • We try to understand the environment in which Blot’s code runs.

Back-end

  • Reliability is the most important attribute of your software. We dislike software that is not dependable.
  • Speed is the second most important attribute. We dislike software that is slow. Blot involves lots of i/o, like reading files from a disk or syncing a file over a network. Because of this, most of what really needs to be optimized is i/o. Nothing is especially computationally intensive. Avoiding even one external HTTP request from a function saves much more time than endless language-level performance optimizations.

Front-end

  • Speed above everything. We run almost everything sent to the client through as many build-time minifiers and compressors as is reasonable. We want to improve the speed of Blot. We also use a neat script called instant.page to begin fetching a page when a reader hovers over a link.

  • As little JavaScript as possible. In general, we want to do as much computation as possible on the server, as little as possible on the client. This is because we control the server, but not the client.

Tools

Web server

  • nginx as reverse proxy. Specifically, we use a distribution of nginx called OpenResty which comes with a Lua interpreter. This means we can take advantage of the excellent lua-resty-auto-ssl to handle SSL certificate issuing and renewal through Let’s encrypt. The reverse proxy is exposed to the internet and handles SSL termination, static file delivery and caching. Anything else is passed to the application server.
  • Node runs our application server and uses the Express framework.

Database

  • Redis for all data that isn’t efficient to store on disk. Redis runs on the same machine as the reverse proxy and application servers, which talk to it over a Unix socket. It’s backed up every hour to S3, and once a day to Backblaze B2, outside AWS. The hourly backups are kept for a day, the daily ones for a week and the weekly ones for a month. Originally we selected Redis as a database because we found the simplicity of a key-value store appealing.

CDN

  • Bunny is faster and cheaper than Cloudfront. It serves cdn.blot.im: images, stylesheets, scripts and other files your site links to. Your site’s pages come straight from our server. We were burnt with a bad Cloudfront bill due to a configuration issue with the video on Blot’s homepage and were annoyed enough to take our business elsewhere.

Version control

  • git was our first choice and so it remains.

Testing

Excellent JavaScript libraries

Development environment

  • macOS is the operating system on which we write Blot’s source code.
  • Docker
  • Visual Studio Code is the text editor in which we write the code. We still aspire to learn how to use vim.
  • Claude Code writes much of the code, and Codex reviews each pull request before we merge it.
  • iTerm is where we run the code.
  • ESLint and Prettier lint and format the code, in a pre-commit hook and in CI.
  • All of this runs on a 12-inch MacBook with an Intel 1.2 GHz m3 processor and 8 GB of RAM. I do not have an external monitor since it is important to be able to put my desk into a state with no visible technology.

Mistakes

This page describes some of the poor decisions we have made.

Not using a CDN (2019)

In 2019 we stopped using a CDN (AWS Cloudfront in front of an S3 bucket), instead opting to use Blot’s server and attached SSD hard drive to serve all the static files for each site. The purpose of this was to reduce the build latency for new posts and the number of moving parts in Blot’s infrastructure. We’d also like to learn more about serving static files effectively at scale.

A few weeks after this change we noticed that images were loading slowly when served by Blot. Even small ones. Really slowly. To verify slow load times we used curl. Here are a few numbers from Blot:

curl -Lo /dev/null -skw "%{speed_download}\n" http://portfolio.blot.im/_image_cache/a4f12fbe-fceb-42be-8903-f742e3c3c10b.jpg

- 180278.000
- 230055.000
- 182060.000
- 218688.000
- 156734.000

And by comparison, here are some from flickr:

curl -Lo /dev/null -skw "%{speed_download}" https://farm9.staticflickr.com/8624/16031381354_11bae45c3e_b.jpg

- 794999.000
- 894288.000
- 1017110.000
- 987376.000
- 324241.000
- 1097168.000

Where to begin to diagnose this problem? It seems like there’s a bottleneck. We needed to work out where the bottleneck is. First, we used fio to measure disk read/write:

aggrb=8639KB/s, minb=8639KB/s, maxb=8639KB/s

I used iperf to measure network throughput out of AWS instance to my machine on a fast commercial internet connection. Here are a few results:

35.9 Mbits/sec 28.4 Mbits/sec

We installed iftop to visualize bandwidth

We thought it might be something to do with proxy buffering but since NGINX was serving the image (and not node) the proxying was not the culprit

Download speed for an image on Blot is about 424.657534247 KB/s. What gives? Imgur is giving us 2989.071038251KB/s for a js file.

Finally we discovered that AWS offers a service called enhanced networking. It was installed but not activated on our instance:

We read more about enhanced networking on reddit. Then AWS’s guide to determining whether it is enabled.

We installed the aws cli and created a new user ‘aws-cli’ to manage the instances, we configured it for oregon (us-west-2). modinfo needed to be run as root.

Will enhanced networking help? What are the downsides? Why isn’t it enabled by default?

We tried adjusting the MTU (MAXIMUM TRANSFER UNIT) size.

Initially, the instance had jumbo frames enabled (mtu=9001), which we reduced to 1500, then did not observe any improved throughput.

Finally we span up a linode in California to see if the issue might be latency related. From CA

  • 4057573.000
  • 4070404.000
  • 4065736.000
  • 4077597.000
  • 4024071.000

We then used iperf to verify the difference:

west-coast linode -> oregon-ec2 instance: 251 Mbits/sec east-coast linode -> oregon-ec2 instance: 59 Mbits/sec

Apparently latency affects bandwidth for TCP. Ah. Back to using a CDN… and we need to read the RFC for TCP. Oh well, at least we now have some concrete numbers for why people use CDNS. The Bandwidth-delay product seems to be the mathematics underpinning the problem we encountered: