UAT on a Budget: How I Gave a Small Team Safe Testing Without Slowing Down Production
A small team, everyone pushing straight to production, and a platform that emails people, prints labels and writes to the ERP. Here is how we added a UAT site without copying everything twice and without putting a gate in front of production.
· 9 min · uat · deployment · fabric · safety
The problem
Our internal platform runs a jewellery factory: design registration, costing, production tracking, sales orders, finance. A small team builds it, and everyone pushes straight to production. That is not carelessness. It is how a small team keeps up with a factory that changes its mind every week.
The changes are not small, either. In a typical week the team ships new modules, new write paths into the ERP, changes to who can see what, and reworked finance screens, and all of it goes straight to the people running the plant. Most mistakes in that kind of change can still be fixed with the next push. The ones that cannot are the ones that leave the building. The platform sends emails to customers and colleagues. It prints labels on the floor, posts cards in team chats, runs scheduled digests, and writes items, sales orders and production orders into the ERP. A test run against production can do all of those things to real people. I came to this team from a very structured corporate environment, and every instinct I had was telling me to build a UAT site as soon as possible: a place to try a change before it reaches anyone.
The textbook answer is a second copy of everything, kept in sync forever. We had neither the budget nor the time for that, and the team did not want a gate in front of production. So the question became: what is the smallest thing we must keep apart? The answer was writes and side effects. Reads could come from wherever the data already was.
One codebase, one flag
Both sites run the same code from the same repository. Production builds from main. UAT builds from a uat branch, and its deployment sets one environment variable, APP_ENV=uat. With the flag off, every helper described below returns its input unchanged. That is how production stayed exactly as it was.
With the flag on, every database name goes through a map before a connection opens or a query runs. A name with a UAT copy is rewritten to it, so every save lands in the UAT copy of the warehouse. A name mapped to itself is an explicit "read production here", which is how the reporting lakehouse is shared. A name that is not in the map is refused.
That refusal is the most important rule in the design. When someone adds a new store next month and forgets the map, UAT fails with an error. It never quietly reads or writes production. Failing closed costs a confused tester an afternoon. Failing open costs a real order.
The ERP gets the same treatment one level up. Every module that writes to the ERP takes its environment from the site: production writes to the ERP's production environment, and UAT writes to its sandbox. No setting can point either site at the other's ERP.
The side-effect guard
The database map covers saves. Everything else that leaves the building goes over HTTP, so the UAT site installs a guard on the HTTP layer when the server starts. It wraps both fetch and Node's https module, which is the one the storage SDK uses, and checks every outgoing request against a short list of rules:
- ERP calls are allowed only into the sandbox environment.
- The low-code database we are retiring and the document store can be read but not written.
- Workflow triggers are refused, label printing included, and so are chat webhooks and email.
- Calls to the production sites are refused, because their APIs write to production stores.
- File storage accepts writes only into containers named
uat-.
Scheduled jobs are switched off on the UAT hosting project, and the secret they need to run is not set there. Even if a timer fired, the job would refuse to start.
A blocked call fails with a message that begins "Disabled on UAT". Testers learned within a day that this means the safety rule worked, not that the feature is broken.
One lesson came from testing the guard itself. My test harness loads modules as ES modules, where require does not exist. The guard's hook on the https module quietly never installed, every other test stayed green, and the one test that deliberately wrote to production went through. It only failed correctly once the harness provided require. A guard you have never watched refuse something is a guard you are only assuming works.
What gets a UAT copy and what doesn't
Copying everything was never the plan. Each store got the cheapest treatment that still kept writes apart:
The warehouse got a one-off copy. The platform's own records (designs, cases, users, permissions, settings) were copied into a UAT warehouse on the day UAT was built. That took about two minutes. The trade-off is that the copy goes stale.
The ERP already had a sandbox, so UAT simply writes there.
The reporting lakehouse is shared. It is rebuilt by hours of pipelines, and the app cannot write to it anyway, so UAT reads production reports. Reports on UAT show real numbers. They do not show the effect of a test save, and testers need to know that.
Files got twins instead of a copy. The file store holds hundreds of gigabytes of CAD models and photos, so instead of copying it, every container got an empty twin with a uat- prefix in the same account. Writes go to the twin. Reads look in the twin first and fall back to the production file. A delete on UAT writes a zero-byte marker into the twin instead of removing the production file. Editing a production-only file copies it into the twin first. The fiddly part was signed URLs, because a signature names one container. Upload links are always signed for the twin. Read links have to check which container holds the file, which turned a set of synchronous helpers async. That is the kind of change where a missed await puts an empty object into a JSON response with no type error, so I checked every call site by name.
Reads became the tester's choice. A week in, someone asked whether what they were seeing on UAT was production data. The honest answer was "partly", and the stale warehouse copy was the reason. So the UAT site got a "Read from" picker: Production or UAT, while every save stays on UAT whichever is picked. Three rules keep it safe:
- Only page views follow the picker. The request layer tags GET requests with the choice and strips the tag from everything else. A save therefore reads and writes UAT from start to finish, and can never read the next free number from production and insert it into the UAT copy.
- A statement may read production only if it provably cannot write. It must start with
SELECTorWITH, and no write or control keyword may appear once comments, strings and bracketed names are stripped. Any doubt sends the read to UAT. - Permissions always come from UAT. Otherwise someone granted access only on UAT would be let in or refused depending on the picker.
My first version skipped the shared query cache for production-mode views. It would have been correct, and it would also have sent every permission check straight to the warehouse on every page view. We share that capacity with production, and we had already seen uncached permission lookups cause a spike once. Each mode now has its own cache keys, and both stay cached.
The trade-off we documented rather than hid: a record created in production after the copy shows up in Production mode, but a save to it finds nothing on UAT.
A Git model people actually follow
The branch rules had to fit a team that ships straight to production.
UAT is optional. Anyone can push to main, and production rebuilds as before. Nobody waits for UAT.
Move only your own commits. Someone who wants to test first merges their branch into uat and lets the requester try it on the UAT site. Then they move their own commits to main. Nobody merges the whole uat branch into production, because it holds other people's work at different stages of testing.
uat catches up by itself. Every morning a scheduled job asks GitHub to merge main into uat. A merge only adds, so nothing under test is lost. If a test change and a production change edit the same lines, the job leaves uat alone and sends a notification, and the owner merges by hand. The first conflict came on day two: a finance change had been merged into uat before its final version reached main, and the fix was to take main's version.
Each hosting project builds only its own branch. For a day it did not. The branch rule we had written in the hosting config file is not read; the real one lives in the project settings. Until we found that, UAT rebuilt on every production push and competed with production builds.
What I'd do next
Checks before a branch reaches uat or main. Today the lint and the full test suite run inside the hosting build, so a red check stops a deploy but only after the push. I want the same checks on every pull request and on every merge into uat. I also want two UAT-specific tests: one that fails when code names a database missing from the map, and a signed-in smoke test that runs against the UAT site after each deploy. A green build only proves the code compiles and its unit tests pass. It does not prove the UAT site can sign someone in.
Fresh ERP sandbox data. The lakehouse holds a copy of the ERP sandbox's tables too, and it turned out to have stopped refreshing two months earlier. That is why ERP reports on UAT read production. It also means a sales order released into the sandbox from UAT never shows up in a UAT report. Restarting that refresh would let UAT read back what it writes, end to end.
Lessons
Design for how people really work, not for how a process diagram says they should.
People push straight to production, so UAT is optional and production never waits for it. People forget things, so every rule fails closed: an unmapped database is refused, and an unguarded storage client cannot write. People test carelessly, which is the whole point, so the isolation sits on writes and side effects, where carelessness does damage. People will not merge branches by hand every day, so a job does it and only asks for help on a real conflict. And people will ask whether the data in front of them is real, so the answer is a picker on the screen, not a page in a wiki.
The result is a place where people can be careless on purpose. They can create a hundred test orders, delete a photo, or release a sales order into the ERP sandbox, and none of it reaches the factory.