Serverless with Redis Database(less)

Dhaval Nagar
AppGambit
4 min readSep 1, 2021

--

Amazon DynamoDB is a great serverless database but we need more options.

In the previous article, I explored the latest offering from MongoDB, MongoDB Atlas Serverless — A fully serverless pay-per-use MongoDB database.

In this article, we will see another, Most Loved Database as per Stackoverflow survey, Redis, that can be integrated in a pure serverless way.

Redis is the Most Loved Database — Stackoverflow 2020 Survey

Upstash is giving an easy to set up and different endpoints (Redis client, REST, and GraphQL) to use Redis in a pure Serverless way — PAY FOR WHAT YOU CONSUME (Query, Storage, and Data Transfer).

Pay Per Request — You can create the Redis database and access it via the Redis CLI, Redis clients like ioredis, or REST APIs. Upstash does the metering against the commands and you pay only for the APIs called along with Data Storage and Data Transfer cost.

Low Latency — The latency is the biggest advantage of Redis, because of the in-memory data format. Upstash maintains a similar submillisecond level of latency with the no-servers-to-manage format.

Durable Storage — Upstash has added a durable layer underneath the Redis server. Once you save the data, it is also saved on the storage provided by the Cloud provider. For example, if you select the AWS option, the data is also stored on EBS. This helps against server failure.

Edge Caching — REST APIs allow leveraging the Edge-enabled cache to further reduce the latency. This feature increases the per-request cost.

The REST endpoint also offers the Read Only token to make limited READ API calls.

The idea of having a Cache server in front of the Database is also undergoing a lot of discussion. With the breadth of use cases and the newer features, the Cache itself can serve as the primary database.

Please do check the Redis API Compatibility before you decide to use the service.

Pricing

Now the most important part, how is this Serverless!!

Setup

In Upstash, you can create a Redis database via the UI Console, API, or the Terraform provider (https://blog.upstash.com/redis-terraform).

Performance

I built a simple Serverless API application that Writes/Reads data — the API is hosted on the AWS East 1 region and using the Upstash Redis hosted on the same region.

The APIs were tested with the Artillery setup to make 100k read/write calls https://artillery.io/

The scaling part was also consistent. Please check the quotas and limits for more detail.

The lambda functions are pretty simple in invocation. The average invocation time is fairly small.

Keep in mind that the Lambda function execution and Redis instance are in the same AWS region and the Lambda does not have any other dependencies or processing.

What next…

Not every application requires dedicated servers to host Redis — I personally think Upstash is an excellent choice for that kind of use case.

The dashboard could have been better to better understand the analytics.

--

--

Dhaval Nagar
AppGambit

AWS Hero, 12x AWS Certified, AWS SME, Founder @ AppGambit