
brentjanderson
Zero downtime Postgres upgrades | Knock
We recently performed a zero downtime Postgres upgrade at Knock. This blog post goes into details about the Postgres considerations, although the BEAM & Elixir ecosystem were invaluable in managing the cutover process.
Some Elixir-related bits:
- We used
DynamicSupervisor
to start/stop Oban during the cutover. Without going into too much detail, Oban needs aNotifier
to coordinate global state, and we rely on the default Postgres notifier (Although there is a new PubSub notifier that we have our eyes on). This Notifier establishes a persistent Postgres connection that is managed outside of your Ecto Repo, and the easiest way to move Oban over to the new instance was to stop and restart it with a new configuration usingDynamicSupervisor
- Metaprogramming made it easier to build facade interfaces to our Ecto Repos so that database requests could be routed to the old or new database instance, based on the state of a launch darkly flag. Internally, LD uses ETS and a persistent websocket connection, which helps lookups be fast and up to date. ETS is still not quite fast enough for the volume of DB queries in our system, and so we also used
:persistent_term
to set the flag that determined what state we were in during the cutover process. Benchee helped us verify that we weren’t going to have a performance regression. - We looked at Ecto Repo’s
get_dynamic_repo
function, but determined that using a facade was a better fit for our use case. It’s worth knowing what’s available, though, since Ecto comes with a lot of extensibility out of the box. - The concurrency model of the BEAM makes it so much easier to reason about all of the stuff involved in a migration like this. Although you can take a similar approach with most languages, the BEAM didn’t get in the way of reasoning through the specifics of the cutover, especially around how we maintain uptime and data consistency during a cutover like this.
We may do a full post on the BEAM-related details of this upgrade in the future.
Popular Backend topics

Real-time applications come with real challenges—persistent connections, multi-server deployment, and strict performance requirements are...
New

Learning Clojure involves much more than just learning the mechanics. To really get Clojure you need to understand the ideas underlying i...
New

Kotlin v1.4.0 has been released.
Link: Release Kotlin 1.4.0 · JetBrains/kotlin · GitHub
New

How Dgraph was running out of memory for some users, and how Go’s Garbage collector wasn’t enough, and Dgraph team used jemalloc to manag...
New

Hello,
i am facing difficult using webpack when to install within phoenix framework 1.5.7 because the webpack is still version 4.x.x inf...
New

I have being some Elixir open-source contributions and side projects. Oh, and I’m doing them on livestreams on my twitch channel, follow ...
New

Woooooooo! This is such a huge release for it, and 2 years incoming!
In short, the library is now using an updated hyper backend (not j...
New

I did not add this to a “this weekend I’ll learn” like my few other journals as I am decided on using this in the long term.
Last I work...
New

Effectively reading and understanding existing code is a developer’s superpower. In this book, you’ll master techniques for code profilin...
New

Fully updated to Elixir 1.14, this authoritative bestseller reveals how Elixir tackles problems of scalability, fault tolerance, and high...
New
Other popular topics

New

I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New

Please tell us what is your preferred monitor setup for programming(not gaming) and why you have chosen it.
Does your monitor have eye p...
New

No chair. I have a standing desk.
This post was split into a dedicated thread from our thread about chairs :slight_smile:
New

Why, if your answer is yes?
New

On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a ...
New

Not sure if following fits exactly this thread, or if we should have a hobby thread…
For many years I’m designing and building model air...
New

I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New

Chris Seaton, the creator of TruffleRuby has died. It appears from suicide :cry:
He left this note on Twitter on the weekend:
And one...
New

Large Language Models like ChatGPT say The Darnedest Things.
The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New
Latest in Backend
Latest (all)
Categories:
Popular Portals
- /elixir
- /rust
- /wasm
- /ruby
- /erlang
- /phoenix
- /keyboards
- /js
- /rails
- /python
- /security
- /go
- /swift
- /vim
- /clojure
- /java
- /haskell
- /emacs
- /svelte
- /onivim
- /typescript
- /crystal
- /c-plus-plus
- /tailwind
- /kotlin
- /gleam
- /react
- /flutter
- /elm
- /ocaml
- /vscode
- /opensuse
- /ash
- /centos
- /php
- /deepseek
- /scala
- /zig
- /html
- /debian
- /nixos
- /lisp
- /agda
- /sublime-text
- /textmate
- /react-native
- /kubuntu
- /arch-linux
- /revery
- /ubuntu
- /manjaro
- /spring
- /django
- /diversity
- /nodejs
- /lua
- /slackware
- /c
- /julia
- /neovim