Using Upstash Redis as a globally distributed json store
When thinking of Redis, most people assume it's just an in-memory caching layer. But Redis can also persist your data to disk. And with the recent addition of data-types such as json objects, it just might work as a simple (but blazingly fast) json backend for your next project!
In the age of javascript frameworks and single-page applications, storing data as json seems like a logical idea. But storing json in files comes with its own issues like concurrency, latency and granular data access. Upstash Redis is a simple key-value (KV) store, that supports large json objects as its value. And instead of replacing the whole object on every save, you can access and update only parts of the object in an atomic way. For example, you can update a single post by accessing it by its index.
redis.json.set('key', $.posts[index], postToUpdate);
And Upstash Redis is fast and globally replicated! It feels like you’re just working with a local file, or a highly optimized database. I was able to get backend response times of 20ms on Vercel, which is pretty impressive. Upstash Redis also lends itself very well to edge functions. Where global replication of a traditional SQL database poses all sorts of issues, that’s much less of on issue for a string ;-)
Of course, the viability of this solution depends on the complexity of your data, and your querying needs. But I highly encourage you to play around with it, and see if it might work for your next side-project.
Note: this post it not sponsored, just me exploring Upstash and sharing my findings.
Visit Upstash