3 ms·
I've been testing in prod for 20+ years, here are the best practices I suggest: tl;dr: Safety comes in the form of confidence that you will know right away whe
by jedberg 4y ago
I've been testing in prod for 20+ years, here are the best practices I suggest:
tl;dr: Safety comes in the form of confidence that you will know right away when something has gone wrong and can quickly recover from it back to the last known good state.
1) Observability is key. You can't test in prod unless you have really good metrics and monitoring in case you break something. It's also the only way you'll know the test worked. So that has to come first.
2) Automated deployment and rollback. You need your deployments to be fully automated as well as rollback. That way if something goes wrong you can quickly back out the change. It also means that devs can roll out smaller changes, because they don't have to amortize any deployment overhead. If a dev knows it will take 30 minutes minimum to deploy, they won't do it as often. Smaller deployments more often mean smaller blast radii.
3) Automated canaries. Once you have 1 and 2, you can fairly easily build 3. When code is checked in, have it automatically deploy and receive a small portion of traffic. Then have it automatically monitored and compare metrics. If the metrics are worse on the canary, roll it back.
You don't need to automate step 3, it's just a lot easier. But you can totally do step 3 by hand as long as you have 1 and 2.
These steps apply to stateless systems, but they can easily be applied to stateful systems with some small changes. With stateful systems you can still do canaries. But you have to add an abstraction layer between your business functions and their datastore (but you're doing that already right?). In that abstraction layer is where you add the coordination to keep data in sync during transitions from one data store to another (when doing schema changes for example). Or if you're changing the way you write to the data store in any way, so that you can write to both new and old and read from new and old without the code being different between them.
And then lastly you start adding in chaos engineering [0]. If your systems can automatically recover from errors in production, then it can automatically recover from bad deployments.
[0] https://principlesofchaos.org https://principlesofchaos.org
- bradwood 4y agoGood answer. The interesting notion for me here, is the distinction between observability (including SLIs, SLOs, etc, not just ad-hoc observability a la honeycomb.io) and testing in production -- they almost feel like 2 sides of the same coin. As really, the test in production is an experiment that is designed to measure something, which feels like it's just an SLI of some sort. Observability, I agree, is essential, but rather than thinking of it as a pre-requisite as you suggest, I'm thinking of the tests as a form of observability.