Gamma logo

Super fast Hasura with GraphQL edge caching for Gamma’s marketplace

The Stellate Edge Cache is just so fast and, thanks to it, Gamma is now also that fast!

Thomas Osmonson

Core Team Member, Gamma


Increased performance


API traffic reduction

To buy, sell, trade (or evolve) NFTs, you have to be on the Ethereum blockchain, right? Not anymore. Introducing Gamma, an open NFT marketplace on the Stacks blockchain, a blockchain that brings expressive smart contracts to Bitcoin.

Wait, what? You heard right. NFTs and Bitcoin are meeting for the very first time. A match made in blockchain heaven.

As you simmer on that, let’s review how we got here. Verifying transactions on the blockchain began with Proof-of-Work (PoW), where miners compete to finish computational puzzles to validate a block on the blockchain – all for the chance to be rewarded with the network’s token. Now Ethereum 2.0 is moving to a Proof of Stake (PoS) model, where miners offer up some of their crypto in exchange for a chance to mine a block. What’s the promise? Do it well and you’ll be rewarded with more crypto; do it poorly and your crypto will be slashed – high stakes motivators intended to keep everyone on their best behavior. 

Back to Gamma. Stacks (STX) began with a Proof of Burn (PoB) consensus model, where miners “burn” or destroy Bitcoin to validate transactions. Version 2.0 is operating with something entirely novel: Proof of Transfer (PoX). Rather than taking Bitcoin and sending it to a burn address where no one can access it, Bitcoin is committed for a chance to mine STX. Essentially, rather than committing electricity for a chance to mine a block in PoW mining, in PoX mining, you commit an amount of a separate cryptocurrency (in this case, Bitcoin) for the chance to mine a Stacks block. Additionally, Stacks holders can lock their STX up to receive the Bitcoin committed in PoX as yield.

Why are we talking about this? Because Stacks is a big deal. Also, Gamma is a client of Fungible Systems, a web3 crypto studio who helped to rebuild the Gamma marketplace and have publicly expressed their love for Stellate:

Why? It all comes down to performance: the Stellate Edge Cache helped make Gamma super fast.

What’s going on behind the scenes? A look at Gamma’s technical architecture 

Similar to RMRK, Gamma has built their own indexer of the blockchain, which listens to all the events and stores the latest state of all the NFTs in a PostgreSQL database using Hasura. The Gamma website, a Next.js app, then fetches that data from Hasura’s GraphQL API with a combination of Jotai and React Query.

Unfortunately, at Gamma’s scale, which is handling more than 120M GraphQL requests per month, Hasura’s performance just isn’t up to par. With a p99 response time of almost 1.5 seconds, Gamma’s Hasura GraphQL API was simply too slow on its own.

As Thomas Osmonson, co-founder of Fungible Systems, told us: “The real thing that sets any web3 project apart is the UI/UX, and a big part of that, particularly for marketplaces, is performance. Gamma has to be fast.”

Edge caching Hasura’s GraphQL API

Given that the Bitcoin blockchain only produces new blocks once about every 10 minutes, Gamma’s data also changes at most every 10 minutes — making it an ideal use case for caching. 

Thomas added Gamma’s GraphQL edge cache in front of Gamma’s Hasura GraphQL API, and immediately got an overall cache hit rate of 87%, which corresponds directly to a decrease in traffic to their Hasura instance:

Even better, their two most highly requested queries are sitting at a 97% and 92% cache hit rate, respectively:

That, in turn, had a massive impact on performance as cached responses are served in single-digit milliseconds globally. The Stellate Edge Cache reduces Gamma’s p99, p95 and p50 response times by ~500ms each: 1.5s to 1s, 1s to 400ms and 450ms to 5ms, respectively.

As Thomas summarized: “the Stellate Edge Cache is just so fast and, thanks to it, Gamma is now also that fast!”

What are you waiting for?

It takes less than 5 minutes to set up a fully functional CDN for your GraphQL API.