Persistent storage for Edgegap game servers
Edgegap starts a fresh container for every match and throws it away when the match ends — disk, files and all. Here's how to keep match state, saves and results anyway, in about ten minutes.
Why your data disappears
An Edgegap deployment is a container that exists for one match (or one session). When it stops, everything written to its disk goes with it — Edgegap's own docs note that even logs are deleted when a deployment terminates unless you set up external storage. The next match starts on a clean image, often in a different city.
So anything that has to outlive a match — results, player progress, a world state to resume — has to leave the container before it stops. The simplest way is an HTTPS call to storage that lives somewhere else. That's what Dorage is.
What you'll set up
- A Dorage account and an API key (the Free plan is enough to try this).
- The key as a hidden environment variable on your Edgegap app version.
- A small client file in your Unity server project.
- Saves at match start, during play, and before the server stops — and a load when the next server starts.
1. Create a key
Create a free account, open your dashboard and create a key — name it after the game or environment, e.g. Production servers. Copy it straight away; it's only shown once.
2. Add it to your Edgegap app version
In the Edgegap dashboard, open your application, edit the app version your servers run, and add two environment variables. Edgegap injects app-version variables into every deployment of that version.
| Key | Value | Hidden? |
|---|---|---|
| DORAGE_URL | https://api.dorage.co.uk | No |
| DORAGE_KEY | dg_live_… | Yes — Edgegap recommends hiding secrets |
Keep the key on the server side only. Never put it in a game client build — anything shipped to players can be extracted.
3. Add the client to your server project
Download DorageClient.cs into your server project's Assets folder. It reads the two variables, retries with backoff if the network blips, and if every attempt fails it writes the data to a local file and the log so nothing vanishes silently. Not using Unity? It's plain HTTPS — see the API docs.
4. Choose what to save under
Dorage stores each save under a match ID and a slot, both names you choose. Pick the match ID by what has to find the data later:
- Your own match, lobby or world ID (from your matchmaker or backend) — use this for anything a later server needs to pick up, because a new deployment gets a new Edgegap ID.
- Edgegap's deployment ID, available inside the container as
ARBITRIUM_REQUEST_ID— handy for per-deployment records such as match results or debugging, so you can line saves up with Edgegap's dashboard.
Slots are just labels: start, end, full, diff, results — whatever suits your game.
5. Save before the server goes
The rule that matters: finish the save before the container stops. If your server ends its own deployment (Edgegap injects ARBITRIUM_DELETE_URL and ARBITRIUM_DELETE_TOKEN for this), wait for the save first:
using System; using System.Collections; using UnityEngine; using UnityEngine.Networking; public class MatchLifecycle : MonoBehaviour { string matchId; // your own match/lobby ID from your matchmaker public IEnumerator EndMatch(MatchResult result) { bool saved = false; yield return DorageClient.Save(matchId, "end", JsonUtility.ToJson(result), ok => saved = ok); if (!saved) Debug.LogError("End-of-match save failed; data written to the fallback file"); // now it's safe to let Edgegap stop this deployment var url = Environment.GetEnvironmentVariable("ARBITRIUM_DELETE_URL"); var token = Environment.GetEnvironmentVariable("ARBITRIUM_DELETE_TOKEN"); if (!string.IsNullOrEmpty(url)) { using (var req = UnityWebRequest.Delete(url)) { req.SetRequestHeader("authorization", token); yield return req.SendWebRequest(); } } Application.Quit(); } }
Matches don't always end politely — a crash, a timeout or a stop from your backend can end the container early. So don't rely on one save at the end: save at the start of the match and at sensible checkpoints too. Then the worst case is losing what happened since the last checkpoint, not the whole match. Keep saves off the hot path — they're coroutines, so start them and carry on.
6. Load it on the next server
When a deployment starts and needs earlier state, fetch it by the same match ID:
StartCoroutine(DorageClient.Load(matchId, "end", (ok, json) => { if (ok) state = JsonUtility.FromJson<MatchState>(json); else state = MatchState.New(); // first run, or nothing saved yet }));
Big game states: compress, and save the difference
If your state is more than a few hundred KB, don't upload all of it every few minutes:
- Compress it. JSON usually shrinks 5–10× with gzip. Send it as binary with
DorageClient.SaveBytes(matchId, "full", gzipBytes, "application/gzip"); you get the same bytes back fromLoadBytes. - Save a full snapshot rarely, and a diff often. Write a compressed
fullslot when the session starts and ends. In between, overwrite onediffslot with the changes since that full save. On load, fetch both and apply the diff. A crash costs at most one diff interval, and storage stays flat. - Re-base when the diff grows past about a third of the full save: write a new full save and clear the diff.
Plans allow saves up to 256 KB on Free, up to 15 MB on Studio — see pricing.
Undo a bad save
Every save to the same match and slot keeps the previous versions (how many depends on your plan). If a bug writes rubbish, list the versions and put a good one back:
curl https://api.dorage.co.uk/v1/matches/m-0042/end/versions -H "Authorization: Bearer $DORAGE_KEY" curl -X POST https://api.dorage.co.uk/v1/matches/m-0042/end/revert/3 -H "Authorization: Bearer $DORAGE_KEY"
Questions
Where is the data, and how far is it from my servers?
Dorage runs in Finland, with nightly backups in Germany. Your Edgegap servers might be anywhere, so a save is a round trip of tens to a couple of hundred milliseconds depending on region — fine for checkpoints and match ends, not something to call every frame.
What happens if Dorage can't be reached?
The client retries with backoff, then writes the data to a local file and the server log, so you can recover it from Edgegap's logs while the deployment is alive. Design your game so a failed save is survivable.
Can game clients call Dorage directly?
Not with your key — it would be extractable from the build. Have the server do the saving.
Is Dorage part of Edgegap?
No. Dorage is an independent service from Oarsman Software Ltd. It works with any host that runs containers — Edgegap is just where the problem bites hardest.
Try it on your next build
Free plan, no card. Two environment variables and one file.
Start free API docs