1/7 Problem: How to scale trading/liquidation engines up to 500k/1M/10M users? 100k users are manageable, but eventually single threaded architecture will bottleneck growing number of users.https://twitter.com/paoloardoino/status/1238965074427088903 …
-
Show this thread
-
2/7 * The order book (OB) for each pair is run on a single thread, with its own I/O queues. * User data UD is deterministically sharded among different threads * Liquidation engine (LE) is a set of threads with direct mem access to user data threads (positions, balances, ..)
1 reply 0 retweets 6 likesShow this thread -
3/7 * LE interacts with OB via in-mem priority queue. * LE adds to a liquidation-order (LEO) enough meta-info for the order book thread to evaluate if liquidation should still happen, bankruptcy price, ...
1 reply 0 retweets 4 likesShow this thread -
4/7 * Each LE sorts users by risk (probability of getting liquidated). * Improvement: a single shared sorted map can be generated across the threads
5 replies 0 retweets 5 likesShow this thread -
Replying to @paoloardoino
Re improvement: perhaps an rbtree ordered by an f() that provides the same ordering but price-independent (so no need to re-sort on each tick as probabilities shift), 1 for longs, 1 for shorts. There is always a "first to be liquidated" position per side independent of price.
1 reply 0 retweets 0 likes -
Replying to @omidaladini
Yup, we are using RBTrees internally. Both for our books and for liquidation priority.
1 reply 0 retweets 0 likes -
Replying to @paoloardoino
there is also lock-free concurrent rbtree designed in publications but no production ready implementations so far :-/
1 reply 0 retweets 0 likes
True. Our design isolates pairs in separate threads, so you don't have to worry of cross-thread locking on RBTrees. You really want base data structures as fast as possible.
-
-
Replying to @paoloardoino
And hence the isolated margining. Interesting trade-off.
0 replies 0 retweets 0 likesThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.