# Priority Queue Matching

While a queueing model could be used, it could be exploited by numerous accounts supplying tiny amounts, causing high gas costs for borrowers. Instead, we use a <mark style="color:blue;">**priority queue matching**</mark> system that sorts users by descending volume, ensuring that higher volumes are matched first. For each new request, the protocol arranges the top 8 opposite requests by volume to respond. Below is an example.

<figure><img src="https://4226119492-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkWffCRtT7sEuuCxLsLGz%2Fuploads%2F0YWgglp4Mq0Atz7a0HoM%2FPriority%20Queue%20Matching.png?alt=media&#x26;token=e6b1b580-97b0-4f49-a7a3-07c30b0523b2" alt=""><figcaption><p>Example: Priority queue matching</p></figcaption></figure>

1. The initial state: Supply 1 is 800 USDC, supply 2 is 1000 USDC, and supply 3 is 500 USDC.
2. When borrow 4 is requested, the priority goes to supply 2.
3. After matching order 1, supply 1 remains at 800 USDC, supply 2 at 600 USDC, and supply 3 at 500 USDC.&#x20;
4. Thus, for borrow 5, the next priority is supply 1.
5. After matching order 2, supply 1 is 300 USDC, supply 2 is 600 USDC, and supply 3 is 500 USDC.
6. Hence, for borrow 6, the next priority is supply 2.
7. Then, matching order 3 is processed.
8. Unmatched amounts of supply 1 (300 USDC) and supply 3 (500 USDC) fall back to the underlying protocol.
