15 Apr Introducing ‘Hive’ – A distributed matching engine for digital asset trading
This week’s performance update was focused around the deployment of Hive — a distributed, multi-threaded & multi-process matching engine built around speed, stability and scalability.
Electronic Matching Engines
A matching engine is the core software behind an electronic, computer-driven trading platform like Bitfinex. A far cry from rowdy floor traders, cryptocurrency trading (and that of most other financial instruments) is now almost entirely enabled by electronic matching engines and the software supporting this.
Matching engines work by matching up trades on a platform, allocating bids and offers amongst competing traders by means of certain set of rules (algorithms). Through an increasingly efficient order allocation process, electronic matching engines have worked to drive down transaction fees to pennies whilst improving market quality (lower spreads, improved order book depth).
As a by-product of this, the speed at which one can receive, interpret and react to market information, in both relative and absolute terms, is now a fundamental consideration for both traders and exchanges seeking a competitive advantage.
Recent platform updates on Bitfinex have focused on transitioning away from a single-threaded matching engine towards a distributed, high-performance, multi-process system.
Referred to as Hive, this system allows for increasingly efficient order execution & improved scaling capabilities by separating workloads amongst multiple ‘instances’, or workers. Instances communicate via Grenache to allocate and execute trades, spawning new workers in times of high load (and vice versa).
Engine Performance Improvements
Due to improvements brought on by Hive, traders on Bitfinex now react more quickly to price movements and changing market conditions. The new architecture enables Bitfinex to maintain high performance in the face of a growing user base, new tradable assets and unforeseen spikes in trading activity.
The distribution of the matching engine ensures that order matching capacity (and latency) remains unaffected by periods of high order throughput. This minimises chances of order rejection due to system overload, even under heavy load.
In internal testing, Hive has scaled up to 100x the number of orders handled in the current market. The deployment of Hive has resulted in a complete order execution time of 14ms, down 10x relative to pre-deployment. This includes the pre-risk check (heaviest part), order matching (microseconds) and execution reporting. Theses results are based on initial tests and are likely to improve further as we work to optimise Hive integration.
Hive also comes with full support for new order types (e.g. position reduce-onlymarginorders), order level flags to prevent self-trading, FX virtual books and support for a number of additional gateways, including Ethfinex DEX gateway and FIX.
On a normal ADSL + VPN: 146ms for full roundtrip (from user perspective), 14ms elapsed between the order has been accepted by our API gateway and been fully executed / confirmed back. Not bad for hive-v1.0 and we just started. pic.twitter.com/EjlfWxDYQl
— Paolo Ardoino (@paoloardoino) March 22, 2018
The Decentralisation of Ethfinex
On the topic of Ethereum, Hive puts the groundwork in place for the decentralisation of Ethfinex. Through adding support for expiry times for orders into the engine — a necessary component for the matching of 0x format, non-custodial orders — as well as adding several other flags, the road is paved for the launch of the Ethfinex non-custodial API and decentralised trading portal.
A new gateway API will allow these Ethereum based order promises (signed and authenticated using a trader’s private key) to be submitted into Hive and treated agnostically like any other order, up until the point of execution when they are settled with atomic swaps on Ethereum.
The deployment of Hive sets a new performance standard for digital asset trading engines and puts the groundwork in place for future development, decentralisation & scalability efforts.
Stay up to date with Bitfinex on Twitter, LinkedIn, Facebook & Support.
All our development libraries are open-sourced. If you are interested in learning more about these, please visit our Github.
Join us on our mission to create the most innovative & industry-leading cryptocurrency exchange.