Simon Willison’s Weblog

Saturday, 18th November 2017

Monodraw for macOS (via) Spectacular OS X application for drawing ASCII art diagrams—it’s basically OmniGraffle for ASCII art. The output is beautiful, and it even lets you do things like draw connecting arrows between boxes and then re-arrange the boxes such that the arrows keep up with your changes. # 6:58 pm

Scaling Postgres with Read Replicas & Using WAL to Counter Stale Reads (via) The problem with sending writes to the primary and balancing reads across replicas is dealing with replica lag—what if you write to the primary and then read from a replica that hasn’t had the new state applied to it yet? Brandur Leach dives deep into an elegant solution using PostgreSQL’s LSN (log sequence numbers) accesesed using pg_last_wal_replay_lsn(). An observer process continuously polls the replicas for their most recently applied LSN and stores them in a table. A column in the Users table then records the min_lsn valid for that user, updating it to the pg_current_wal_lsn() of the primary whenever that user makes a write. Combining the two allows the application to randomly select a replica that is up-to-date for the purposes of a specific user any time it needs to make a read. # 6:42 pm