You want to move a bucket's traffic to a new S3 endpoint and nobody should notice. Copying the files is the easy part (see moving a bucket with rclone). The hard part is the hours while apps keep writing.
One nginx in front of both endpoints can do it with four small config files. We ran it with a client writing and reading the whole time, through every switch, and counted what broke. Short version: nothing failed, but two things quietly went wrong, and both are easy to fix if you know to look.
The four stages
| Stage | Reads go to | Writes go to | nginx pieces |
|---|---|---|---|
| 1. Before | old | old | proxy_pass |
| 2. Mirror | old | old, and a copy to new | mirror, mirror_request_body on |
| 3. Flip | new, old if new says 404 | new, and a copy to old | proxy_intercept_errors on, error_page 404 = @old |
| 4. Done | new | new | proxy_pass |
Stage 3 keeps a copy of every write going back to old, so you can flip back without losing anything. Each stage is one file and a graceful <code>nginx -s reload</code>, which does not drop open connections.
The config
- The
ifinside/_mirrorkeeps reads from being mirrored: GETs return 204 at once, only writes go on. $request_uricarries the query string, which matters for multipart parts (see below).Hostmust pass through untouched. It is part of the SigV4 signature, so a proxy that rewrites it getsSignatureDoesNotMatch.
The test
- Two S3 gateways (rclone 1.76.0
serve s3) on one Mac, behind nginx 1.31 on loopback. Both accept the same access key, because a proxy cannot re-sign a request. - 2,000 objects (1 to 64 KB) created on old first. Then 4 client workers (boto3, retries off, so one failure is one failure) ran for the whole test: write a new object, read back two random older ones, check the SHA-256.
- Switches between stages happened while the workers ran. Between stages we copied the backlog with
rclone copy old new --ignore-existing.
Result: zero failed requests
| Stage | Writes | Reads | Errors | Wrong content | PUT median / p95 | GET median / p95 |
|---|---|---|---|---|---|---|
| 1 old only | 1,020 | 2,040 | 0 | 0 | 2.7 / 6.1 ms | 1.5 / 3.0 ms |
| 2 mirror on | 1,125 | 2,250 | 0 | 0 | 3.1 / 8.0 ms | 1.7 / 3.8 ms |
| 2 new gateway down 6 s | 847 | 1,694 | 0 | 0 | 3.1 / 7.5 ms | 1.7 / 3.9 ms |
| 2 mirror on again | 341 | 682 | 0 | 0 | 3.7 / 9.3 ms | 1.9 / 4.3 ms |
| 3 new first, old fallback | 1,210 | 2,420 | 0 | 0 | 3.1 / 8.6 ms | 1.8 / 4.3 ms |
| 4 new only | 950 | 1,900 | 0 | 0 | 3.4 / 8.4 ms | 1.9 / 3.7 ms |
5,493 live writes plus the 2,000 starting objects, 10,966 reads, 0 errors and 0 hash mismatches. At the end all 7,493 acknowledged objects were on new with the right content. The mirror added about 0.4 ms to the median PUT on loopback; a real network will differ, so measure on your own link.
Trap 1: the mirror is best effort
nginx ignores the response of a mirrored request. If new is down or errors, the client still gets a 200 from old and never hears about it. We stopped the new gateway for 6 seconds in stage 2:
| Moment | Objects on old | Objects on new | Only on old |
|---|---|---|---|
| Before the outage (after the first backfill) | 3,993 | 3,993 | 0 |
| After the 6 s outage | 5,306 | 4,584 | 722 |
After rclone copy --ignore-existing | 5,330 | 5,330 | 0 |
The client saw no error for any of the 721 small writes in that window. That is why a compare-and-copy pass before every flip is not optional. Run it, and run it again right before stage 4: <code>rclone check old: new:</code> lists what differs.
Trap 2: multipart uploads do not mirror
We uploaded a 20 MiB file with boto3 in 8 MiB parts through the stage 2 proxy. It landed on old. It never appeared on new. (It is one of the 722.) Each gateway hands out its own UploadId when the upload starts, so the mirrored UploadPart and CompleteMultipartUpload calls name an ID that new has never heard of, and nginx throws away the error.
- Large files need the compare-and-copy pass, or a short freeze on big uploads during stage 2.
- Plan on every object over your SDK's multipart threshold (8 MiB in boto3) being a candidate for that pass.
The fallback: what a read costs
In stage 3 we deleted 40 objects from new on purpose, then read them. All 40 came back correct from old. A missing key is a different cost: the log line for a key that exists nowhere shows two upstream attempts, <code>new/404</code> then <code>old/404</code>, and the client gets 404.
Apps that probe for keys that often do not exist pay for two requests each until you drop the fallback.
Trap 3: dropping the fallback too early
In a first run we went to stage 4 without the last check. The 40 objects we had deleted from new were still missing. The workers kept reading random keys, and <b>14 of 1,871 reads</b> in stage 4 picked one of those 40 and got NoSuchKey. A second run with the check and one more <code>rclone copy</code> before stage 4 had 0 errors. In real life the 40 are whatever the mirror dropped.
Order of work
- Start stage 2 (mirror on) and watch the old and new object counts.
- Backfill the history with
rclone copy. Compare. Repeat until only in-flight objects differ. - Flip to stage 3. Keep writes mirrored back to old for as long as you want a way back.
- Run the compare again, copy what is missing, and only then move to stage 4.
- Last: point the clients' DNS or endpoint setting straight at new, and retire the proxy and old.
Where this does not work
- Different credentials. The same signed request goes to both sides. If old and new use different access keys or hostnames in the signature, new will refuse the copy. A signing proxy or dual-write in the app is the way then. We did not test either.
- Lua routing. OpenResty was not installed here, so nothing in this article needs it; we did not test Lua-based routing.
- Real network and real providers. The lab is loopback with a simple S3 server. Numbers about latency are for comparison between stages only.
Keep an eye on retries under 503 SlowDown while a mirror doubles your write requests for a while.
S3-compatible buckets with scoped access keys and no egress fees. Copy a bucket across, then cut over.
Explore tport.spaceTest record and sources
- Run on 2026-11-14, one Mac, loopback. 18,525 requests through the proxy in the final run.
- nginx docs: ngx_http_mirror_module (mirrored responses are ignored,
mirror_request_body), ngx_http_proxy_module (proxy_intercept_errors). - AWS docs: Authenticating requests with Signature Version 4 (the Host header is signed).