Tableflip Example
This example demonstrates how to use tableflip for graceful upgrades in a Go application.
What is Tableflip?
Tableflip is a library that allows you to update the running code and/or configuration of a network service without disrupting existing connections. It achieves this by starting a new process, transferring clients to it, and then exiting the old process.
Goals of Tableflip
- No old code keeps running after a successful upgrade.
- The new process has a grace period for initialization.
- Crashing during initialization is acceptable.
- Only a single upgrade is ever run in parallel.
- Tableflip works on Linux and macOS.
Steps
-
Build v0.0.1 Demo:
go build -o demo main.go
-
Run the Demo and Create a GET Request to
127.0.0.1:8080/version
:[PID: 123] v0.0.1
-
Prepare a New Version:
- Change the
main.go
to update the version to "v0.0.2". - Rebuild the demo:
go build -o demo main.go
-
Kill the Old Process:
kill -s HUP 123
-
Create the Request to the Version API Again:
[PID: 123] v0.0.2
The client is completely immune to server upgrades and reboots, and our application updates gracefully!