Ask HN: Do you test in production?
31–40 of 75 posts
Re: Ask HN: Do you test in production?
#32The way we did it safely is just as you say: creating fabricated users/organizations/configurations with data generators injecting into the system.
Faking data to look realistic is always challenging, but we used this cool library written by an early segment engineer: https://github.com/yields/phony
Not perfect but works well enough! And it's super simple. :-)
Re: Ask HN: Do you test in production?
#33Re: Ask HN: Do you test in production?
#34That did require having multi-tenancy support, and there was a need to suppress some security features by whitelisting the IP of the test app.
Re: Ask HN: Do you test in production?
#35Re: Ask HN: Do you test in production?
#36tl;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.
Re: Ask HN: Do you test in production?
#37Then I turn it on just for the user I test with in prod. Then I test in prod.
When it's time to enable the feature for the rest of the users, the same system let's me slowly dial up which users can see the feature. This separates deployment from launch, which is also a great best practice.
Re: Ask HN: Do you test in production?
#38I would prefer not having to do that at all though.
Re: Ask HN: Do you test in production?
#39But it is also useful to get very close to "test in prod" without actually risking anything.
Actually executing data-changing code for testing is actively discouraged, though.
1) the current system takes a snapshot of the production db at the end of the day and uses it to repopulate from scratch this "staging" environment. In past cases I had to accept less frequent updates, though.