Watch the video
Learn the fundamentals of sales tax
TaxJar API Performance & Scalability Remains Industry-Best with Elixir
byJanuary 21, 2021
Why Every Millisecond Counts for eCommerce Sellers
When your customers are buying online, every millisecond matters. Every 1,000 millisecond or 1 second reduction in page load time for Walmart resulted in a 2% conversion increase. Every 100 milliseconds for Mobify resulted in a 1.11% conversion increase.
Sales tax calculations also have to be accurate and reliable. As a merchant your sales tax API is mission critical. If it goes down you’re not collecting sales tax from your customers. And if you’re not collecting sales tax from your customers, you’re going to pay that sales tax out of your pocket when it comes time to file.
We guarantee 99.99% uptime and provide backup tax rates just in case. Our competition commits to a minimum service uptime of 99.5%. Here’s the difference in allowable downtime between 99.99% and 99.5%:
Over 1 day of downtime a year is not acceptable. Combined with higher response times, your sales tax API alone could be costing you tens of thousands of dollars a year in lost revenue.
TaxJar’s API Migration from Ruby to Elixir
Back in 2018, our engineering team made the strategic decision to begin migrating our Ruby API endpoints over to Elixir. By August 2019, 100% of our sales tax calculations were running on the industrial-strength, high-performance, and fully distributed Erlang VM.
Elixir is a functional, concurrent programming language that allows us to leverage the scalability of Erlang. WhatsApp uses Erlang to reach over two million concurrent users on a single node. AdRoll uses Erlang to process 500k+ bid requests per second. TaxJar now uses Erlang to perform hundreds of millions of sales tax calculations a month for entire platforms and Fortune 500 companies. At the same time, we brought down our AWS server costs substantially.
TaxJar used a canary release strategy by directing a subset of traffic to the new Elixir endpoints and the remaining traffic to the older Ruby endpoints via Amazon API Gateway. We gradually increased the number of API calls made to Elixir over time until we were confident in handling 100% of API requests with Elixir on production.
To gain that confidence, we designed an internal project known as Kodan to replay millions of historical API requests through our new Elixir API using Amazon Athena. This allowed us to discover edge cases and unexpected scenarios that may have resulted in different behavior compared to our Ruby API. Our goal was to ensure full parity between both APIs on how they receive and process incoming requests. Kodan made it possible to catch these differences before they affected any users on production.
Handling requests identically between the APIs led to some interesting challenges along the way. One was duplicating Ruby’s permissive type system inside Elixir. Ruby allows for many different implicit conversions (e.g. `“”.to_f == 0`) that you won’t find in Elixir. Another challenge was mirroring the sorting behaviors found in Ruby so the ordering of line items and other collections of data in a response remained consistent.
Overall, the transition from Ruby to Elixir went smoothly. It required a shift in thinking to write code in a functional way, but it made testing that code much simpler. Elixir’s functional nature allows for very small, isolated units of change and it gave us confidence that other areas of our codebase wouldn’t be affected. Pattern matching helped us write cleaner code in our complex validation layer that was once encumbered by conditional statements in Ruby. The language features of Elixir that are just under the surface like the `with` statement, protocols, and behaviours improved our productivity.
As a result of switching from Ruby to Elixir, our average response times decreased from 75ms to 18ms. Infrastructure and server costs were dramatically lowered. When Black Friday and Cyber Monday rolled around in 2019, our API didn’t break a sweat. TaxJar’s API is built to power entire eCommerce platforms and marketplaces. It’s built to last.
Ready to get started with TaxJar’s API? Head on over to https://salestax.dev and review our API documentation. If you’re interested in solving big problems at scale with Elixir, check out our jobs page to apply and learn more!
Please note: This blog is for informational purposes only. Be advised that sales tax rules and laws are subject to change at any time. For specific sales tax advice regarding your business, contact a tax advisor.
The basics of US sales tax
Learn the fundamentals of sales tax.Watch the video