My first piece of negroni middleware. Tada. Replicator allows you to replicate traffic to another domain. This is sometimes called T-ing traffic and can be done at a hardware level.
Inspired by a blog post that described send testing a re-write by placing an iframe on every page of a site. This allowed them to monitor unknown or undocumented parts of the site. I guessed there was a better way to do this in go, and middleware makes it super easy.
Replicator lets you duplicate all requests to a new location, like
beta.example.com or a staging environment. It also allows you to define a percentage of traffic and an option to not guarantee deliverability. This has minimal impact on the speed of the current request.
Why Use Replicator?
Getting real traffic is a wonderful thing as users abuse a system, the have a knack of breaking the unbreakable. So you're able to route real traffic to a staging environment. This could be just a percentage if you want to just sample, like extra eyes on per-production code.
Replicating real traffic allows you to also monitor performance before something goes live. Using existing logging middleware in negroni, you're able to keep an eye on performance.
How to use it?
Include it in the list of middleware, preferably as near to the top as possible. This will ensure that it's sending as raw a request as possible.
There are 3 parameters:
newURL is the new location for the traffic.
meh controls deliverability, I might drop it, and will probably rename it. Setting meh to
true and the application will make a best effort to send the new requests, setting it
false will always send these requests.
percentage this is the percentage of traffic that will be sent.
I've not used this in production. The quality of the tests is dubious and I've not measured performance. Apart from that go use it. I'll be working on improving all of these things in the near future.
If you are using it, or have question, let me know on twitter @john_nye