Screenshot 2026-05-07 at 10.41.57 AM.png

There are many ways backends can talk to each other.

  1. Queues
  2. HTTP
  3. Websockets
  4. Pub sub

All have their own pros and cons. We’ll be using queues.

Starting redis locally

Use docker or a managed service - https://upstash.com/pricing

Publishing the order

import { createClient } from "redis";
import express from "express";

app.post("/order", async (req, res) => {
    // matching
    const userId = req.userId;
    const {type, price, qty, market_id, side} = req.body;
    await client.lPush("incoming-order", JSON.stringify({
        type, price, qty, market_id, side, userId
    }))

})

Subscribing to the order

Create a new bun project called engine or orderbook . Move all in memory variables there

Blocking pop

import { createClient } from "redis";

const BALANCES = {
    
}

const ORDERBOOKS = {
    SOL: {},
    BTC: {}
}

const client = await createClient()
  .on("error", (err) => console.log("Redis Client Error", err))
  .connect();

while(1) {
    const response = await client.brPop("incoming-order", 1);
    console.log(response);
}

Unblocked pop

import { createClient } from "redis";

const BALANCES = {
    
}

const ORDERBOOKS = {
    SOL: {},
    BTC: {}
}

const client = await createClient()
  .on("error", (err) => console.log("Redis Client Error", err))
  .connect();

while(1) {
    const response = await client.rPop("incoming-order", 1);
    console.log(response);
}

<aside> 💡

Question — How does the engine talk back to the HTTP Server?

</aside>