Those who follow the cryptocurrency markets will know that challenges come fast and furious, with huge swings in prices and trading volumes driven by unpredictable developments, all in an environment of rapidly changing regulations. For an exchange with the scope and ambition of Koinex it currently offers trading in more than 50 pairs of cryptocurrencies that leads to a lot of exposure to market volatility.
For example, Rakesh says, three months after the launch, Koinex saw a huge spike in Ripple (XRP) transactions. "It was 50 times the volume we'd seen before," he says. A group of Japanese credit card companies had just announced Ripple support, giving it a huge increase in trustworthiness. The trading volumes ramped up and stayed up. But the PostgreSQL deployment (a tabular database) underpinning the Koinex platform couldn't keep pace with surging demand.
"Everything was stored in a PostgreSQL, and it wasn't keeping up. We had an overwhelming growth in data with read and write times slowing because of large indexes, and CPUs spiking. Moving our deployment to Aurora RDS gave us two times improvement. But it wasn't enough as we could not scale beyond a single instance for writes. We were seeing just one thousand transactions per second, and we wanted to aim for 100,000." If one spike on one cryptocurrency could cause such problems, what would a really busy market look like? Time to aim high.
"We decided to move the 80 percent of data that needed real-time responses to MongoDB's fully managed database as a service Atlas, and run it all on AWS."
The MongoDB Atlas experience
The move was started in January as part of the development of a new trading engine and, as Ankush SharmaSenior Platform Engineer at Koinex, explains, MongoDB Atlas looked like a good fit for a number of reasons. "It had sharding out of the box, which we saw as essential as this gave us the ability to distribute write loads out across multiple servers, without any application changes at all. Atlas also meant fewer code changes, less frequent resizing or cluster changes, and as little operational input from us as possible."
Other aspects of the database seemed promising: "Its flexible data model made it a great fit for blockchain RPC-based communications as it meant we could handle any cryptocurrency regardless of its data structure. MongoDB Atlas is fully managed so it's zero DevOps resources to run, and it's got an easy learning curve."
That last aspect was as important as the technical suitability. "Allocating developer bandwidth is completely crucial," says Ankush. "If we'd stuck with Postgres, creating the new Trading Engine would have been three to four months. That wouldn't have been survivable. With MongoDB we did it in 30 to 40 days." And although he initially wasn't sure MongoDB Atlas would be a long-term solution, its performance convinced him otherwise.
"It scaled out as we needed, and it scaled back so gracefully. There are times when the market is slower, so it lets us track costs to market liquidity. It's working really well for us."
It's continued to free up developer bandwidth, too. "We started off with just the one product on MongoDB but we have eight or nine on it now. We wouldn't have been able to concentrate on the mobile app, or provide historical data on demand to traders if our DevOps team didn't find the database so easy to work with and with so many features."
And long lead times on new products aren't an option in the cryptocurrency market. Over just 17 days in July, Koinex built out and launched a new service called Loop a novel peer-to-peer digital token exchange system designed to deal with controversial regulatory moves by the Indian central bank. "Digital currencies are complex. Policies and technologies are changing all the time so our business often depends on being able build new features quickly, sometimes in just a few weeks. Not only does it have to be done fast but it has to be tested, robust and at scale. It's a financial platform you can't compromise. Time we don't spend managing the database is time we can spend on new features and products, and that's a huge payback."
MongoDB also has the right security features to fit in with a financial exchange, says Ankush: "We have solid protocols limiting who in the company can see what data, with strong access controls, encryption and proper separation of production and development environments. We look to global best practices, and these are all implemented by default in the MongoDB Atlas service."
For a company barely a year old, Koinex has big plans for the future. "Koinex has been leading the digital asset revolution in India," says Ankush. "We give users a world-class experience. The long-term plan is to have multiple digital asset management products available, not just cryptocurrencies. Whole new ecosystems are going to develop. With MongoDB Atlas, we're going to be able to do all the things that other top exchanges do as well as add in our own extras and features."