OOP Design Solution

```python []
BUY_ORDERS = 0
SELL_ORDERS = 1
MOD = int(1e9 + 7)

class OrderBook:
    def __init__(self, order_type) -> None:
        self.order_type = order_type
        self.price_orders_map: dict[int, int] = {}
        self.price_heap: list[int] = []
        self.backlog = 0

    def push(self, price, orders) -> None:
        if price not in self.price_orders_map:
            heappush(self.price_heap, self._heapPriceMap(price))
            self.price_orders_map[price] = orders
        else:
            self.price_orders_map[price] += orders
        self.backlog += orders

    def pop(self, orders):
        best_price = self.peekPrice()
        remaining_orders = self.price_orders_map[best_price] - orders
        if remaining_orders == 0:
            heappop(self.price_heap)
            del self.price_orders_map[best_price]
        else:
            self.price_orders_map[best_price] = remaining_orders
        self.backlog -= orders

    def peekPrice(self) -> int:
        return self._heapPriceMap(self.price_heap[0])

    def orders(self, price) -> int:
        return self.price_orders_map[price]

    def empty(self) -> int:
        return len(self.price_heap) == 0

    def _heapPriceMap(self, price) -> int:
        return -price if self.order_type == BUY_ORDERS else price


class Solution:
    def __init__(self):
        self.buy_book = OrderBook(BUY_ORDERS)
        self.sell_book = OrderBook(SELL_ORDERS)

    def getNumberOfBacklogOrders(self, orders: List[List[int]]) -> int:
        for price, quantity, transaction in orders:
            if transaction == BUY_ORDERS:
                self.settleTrades(price, quantity, BUY_ORDERS)
            else:
                self.settleTrades(price, quantity, SELL_ORDERS)

        res = self.buy_book.backlog + self.sell_book.backlog
        return res % MOD

    def settleTrades(self, price, orders, order_type):
        append_book = self.buy_book if order_type == BUY_ORDERS else self.sell_book
        opposing_book = self.sell_book if order_type == BUY_ORDERS else self.buy_book

        while orders > 0 and not opposing_book.empty():
            # Check if the trade can happen
            best_opposing_price = opposing_book.peekPrice()
            if order_type == BUY_ORDERS and price < best_opposing_price:
                break
            if order_type == SELL_ORDERS and price > best_opposing_price:
                break

            # Perform trade by matching orders
            opposing_orders = opposing_book.orders(best_opposing_price)
            matched_orders = min(orders, opposing_orders)
            orders -= matched_orders
            opposing_book.pop(matched_orders)

        # If there's any unmatched orders, add it to backlog
        if orders > 0:
            append_book.push(price, orders)

```
``` cpp []
const int BUY_ORDERS = 0;
const int SELL_ORDERS = 1;
const int MOD = 1e9 + 7;

class DynamicComparator {
public:
    DynamicComparator(int orderType) : orderType(orderType) {}

    bool operator() (int lhs, int rhs) const {
        if (orderType == BUY_ORDERS) {
            return lhs < rhs; // Max-heap for BUY_ORDER
        } else {
            return lhs > rhs; // Min-heap for SELL_ORDER
        }
    }

private:
    int orderType;
};

class OrderBook {
public:
    long backlog;

    OrderBook(int orderType) 
        :   backlog(0), 
            priceHeap(DynamicComparator(orderType)) {};

    void push(int price, int orders) {
        if (!priceOrdersMap.contains(price)) {
            priceOrdersMap[price] = orders;
            priceHeap.push(price);
        } else {
            priceOrdersMap[price] += orders;
        }
        backlog += orders;
    }

    void pop(int orders) {
        int topPrice = priceHeap.top();
        int remainingOrders = priceOrdersMap[topPrice] - orders;

        if (remainingOrders == 0) {
            priceHeap.pop();
            priceOrdersMap.erase(topPrice);
        } else {
            priceOrdersMap[topPrice] = remainingOrders;
        }
        backlog -= orders;
    }

    tuple<int, int> peek() {
        int topPrice = priceHeap.top();
        int topPriceOrders = priceOrdersMap[topPrice];
        return make_tuple(topPrice, topPriceOrders);
    }

    size_t size() {
        return priceHeap.size();
    }

private:
    unordered_map<int, int> priceOrdersMap;
    priority_queue<int, vector<int>, DynamicComparator> priceHeap;
};


class Solution {
private:
    OrderBook buyBook;
    OrderBook sellBook;
    
public:
    Solution() : buyBook(BUY_ORDERS), sellBook(SELL_ORDERS) {};

    int getNumberOfBacklogOrders(vector<vector<int>>& orders) {
        for (auto& order : orders) {
            settleTrades(order[0], order[1], order[2]);
        }
        return (buyBook.backlog + sellBook.backlog) % MOD;
    }

    void settleTrades(int price, int orders, int orderType) {
        OrderBook& appendBook = orderType == BUY_ORDERS ? buyBook : sellBook;
        OrderBook& matchBook = orderType == BUY_ORDERS ? sellBook : buyBook;

        while (matchBook.size() and orders) {
            auto [bestOpposingPrice, bestOpposingPriceOrders] = matchBook.peek();
            
            if (orderType == BUY_ORDERS && price < bestOpposingPrice) break;
            if (orderType == SELL_ORDERS && price > bestOpposingPrice) break;

            int matchedOrders = min(orders, bestOpposingPriceOrders);
            orders -= matchedOrders;
            matchBook.pop(matchedOrders);
        }

        if (orders > 0) {
            appendBook.push(price, orders);
        }
    }
};
```
['Design', 'Heap (Priority Queue)', 'Simulation', 'C++', 'Python3']