In the December issue of e-Forex, John McGrath’s Expert Opinion, ‘Why Data is the New Hidden Battleground in e-FX’, argued that venues now compete on data rather than execution. From where I sit, building the platforms underneath, the harder fight comes earlier: getting a firm’s own data into one place.
On the customer side, the data was in several disparate locations. Orders were in one system, executions in another. Market data came from a particular set of APIs, and there was another set of files that were created on a daily basis.
Identifying how best to get all of that into object storage was the first conversation we had, because we had to agree on a format. We settled on CSV after considering the tooling, the skill set, and the project team’s preference for supporting the system in the long run. Then came the storage for processing and presentation. Everyone agreed on an open source data store, mainly to avoid vendor lock-in. For those reasons and more, Postgres was declared the winner.
The question the traders kept asking
The question the traders kept asking was simple: give us real-time market insights, with up-to-date market information and analysis. In practice that meant questions like “how did a client’s executions sit against the market at the time?” and “show me this client’s activity alongside the market, today, not tomorrow.”
Answering those means joining two very different kinds of data: a few thousand client orders a day, every one of them important, against millions of market rows a day. This is where the join between market data and actual orders and executions comes into the picture. If the final output is slow or wrong, traders are working with yesterday’s data. It is also the join that nearly sank the platform, and it is where this story goes next.
Why a Postgres-compatible managed database
Before we get there, a word about the default assumption in this market: that trading data needs a specialist store. We chose a managed PostgreSQL-compatible database. Postgres is one of the most popular databases among developers anywhere, it is open source, it has a huge library of extensions and phenomenal community support.
Obviously you do not stop there. You start thinking about what the business needs to keep the database running all the time without the maintenance overhead. Critical systems usually opt for managed services that also offer analytical capability, such as AlloyDB, Aurora or Timescale.
Beyond that, you want a solution that scales storage, offers high availability and reliability, and is prepared for human mistakes, power outages and environmental disasters like flooding. And you want low latency. Read latency of a few milliseconds or less, and write latency to match, decide whether ingestion jobs finish on time. Low latency also saves developers from spending their days waiting on slow infrastructure, and slow infrastructure has a strong correlation with rising project costs.
One note on scope: nothing here touches order matching or routing. This is the system that receives the trades, not the one that makes them.
The shape of the platform
We began with the sources. One was live customer trades, the other was market daily data. Both land in object storage. From there, live customer trades are streamed using a Spark streaming engine (Dataproc or equivalent), and the market daily data is processed through Spark batch. Both sources are then loaded into a schema in Postgres we called Ingestion.
Ingestion schema. Live streaming data, trades and market daily data sit in separate tables. Stored procedures do the complex calculations, transform the data and make it ready for the Transform schema. These procedures are scheduled with pg_cron, the database’s built-in scheduler, in a sequence designed for efficient execution.
Transform schema. Two sets of tables: one holding live streaming data plus trades, the other holding consolidated daily market data plus trades. A different set of stored procedures waits for this data to arrive and processes it on its own schedule, again through pg_cron. The ready data is then inserted into the Presentation layer.
Presentation schema. These tables hold everything needed to serve both the application and the traders.
The transformations are where the work is. The stored procedures calculate metrics by joining live customer trades with market daily data, and market daily data is joined to customer daily data every minute, so the presentation layer always holds the freshest data for end users to act on.
We chose pg_cron for this scheduling rather than an external scheduler for one main reason: keeping the scheduler close to the data. Having a managed Postgres service with analytical processing capability also made the bigger joins run significantly faster.

The join that could have sunk it
Between the Ingestion and Transform schemas we had a cron job that populated rows every minute, with the next run triggering after the current one finished. Occasionally that one-minute run went much, much longer: thirty minutes, sometimes an hour and a half. We began investigating and it was not clear why. We checked the source data, the target data, the requirement documents, the data model. Nothing looked out of the ordinary.
Then I looked at that particular minute’s query and its execution plan. One of the merge joins was processing 400 million records. 400 million! The source tables had a few thousand rows up to about 149,000. Something was not adding up. It had the symptoms of a Cartesian join, even though the plan did not say so and there was a join condition between the tables.
The reason turned out to be slightly complex. The documents we had been given described a metric at a point in time. Because of the complexities of the implementation, the code we wrote was working on a range instead. So rather than joining one row of a table with 140,000 rows of another, we were joining around 3,000 rows covering that range with 140,000 rows. That is how you get to 400 million.
For reading the execution plans I used an open source tool called pev2, which visualises the plan and let me go deep enough to see the Cartesian behaviour for what it was. After rereading the documentation we changed the code to capture the metric from the smaller table at a point in time rather than over a range. The one-minute queries finished in under a minute again, and the ingestion jobs met their timing expectations without building a backlog.
The lesson for anyone running a platform like this: the hard part is not storing the data, it is getting the big join right. Get it wrong and no database will save you. Get it right and a standard one is plenty.

Six decisions that set the bill
When it comes to the running cost of a managed database, there are a few decisions worth making deliberately:
- Instance size. Is the database sized for the day we expect or the day we fear? Oversize and we pay for idle capacity. Undersize and CPU or other resource pressure means the presentation layer gets its data later, or not at all.
- Storage. Do we pay for storage we might consume in future, or only for what we consume today?
- Read replicas. Are the people and processes reading the data competing with the processes writing it?
- High availability. Are we fine with ten minutes of downtime? If not, how much are we planning for?
- Cost anomaly detection. How would we know if a bad query doubled our bill overnight?
- Committed-use discounts. We stayed on demand for the first year on purpose. Once the project has proved itself, that is the time to commit.
The two that mattered most were sizing and cost monitoring, and the join in the previous section is the reason for both.
Running it after go-live
We used pg_cron to schedule and automate the data flow into the Transform and Presentation layers. It kept the business logic as close to the data as possible; we never had to leave the database to do complex processing. It gave us atomic operations and direct SQL execution to turn business requirements into a working codebase.
With a few control tables and some code to populate them, we also built logging that let developers and the operations team see what was going on, and troubleshoot faster alongside the monitoring tools the managed service provides out of the box. It worked well enough that in-database scheduling became the customer’s default for later Postgres projects.
Four questions, then close
If you run a trading business and have never looked at the data platform underneath it, four questions will tell you where you stand:
- Can you see a client’s orders against the market they traded into, without raising a data request?
- How many systems does that answer come from?
- Where does the big join happen, and how was it designed?
- Who owns the platform the day after go-live?
I write this as a database engineer, not a trader, so I will end where engineers end. The data business everyone is now describing rests on a handful of decisions about where data lives and how the sources are joined to match what the business actually needs. Get those right and a database will do wonders. Get them wrong and no strategy will save you.

