How do Databases Compare for Serverless Functions and Containers?

Comparing Serverless Databases: Firestore, DyanmoDB, Cosmos DB, and More

Jacob Jackson
AWS in Plain English

--

Photo by imgix on Unsplash

In the past, almost all databases were single machines running SQL. Latency was low, it was fairly simple, and you did not need to worry about consistency. But times have changed, and now databases must be scalable across multiple machines, connect to potentially thousands of small serverless functions, and remain consistent and secure.

Traditional SQL databases are limited by their technology that expects there to be a stable number of connections. They also can’t deal with a sudden spike in traffic as well. Because of the need for a more scalable database, serverless databases were born. Serverless databases use varying bits of multiple machines to be able to scale up when required. Plus, they are designed to work with short-lived serverless functions and containers. In this article, we will look at different types of serverless databases and how they compare.

Databases

  1. Cloud Firestore
  2. Amazon DynamoDB
  3. Amazon Aurora Serverless
  4. Azure CosmosDB
  5. Fauna

Metrics

  1. Flexibility: How effectively you can query things and things like client support and real-time updates.
  2. Ease of Use: How easy it is to set up and use.
  3. Scalability: How scalable it is for large traffic growth and sudden spikes.
  4. Cost: How expensive it is.

Comparison

Flexibility

Cloud Firestore performs poorly on this metric. While it is great for simple uses, it lacks powerful querying tools, relying on a NoSQL Document Structure. It only supports some filtering and listing, and you will likely use many reads and get lots of unnecessary data if you try to do anything complex. However, it has flexibility in some other areas, like real-time data updates and client connection support. Overall, it is not very flexible, but can be in some areas.

Amazon DynamoDB also has limited querying capability. It also does not support real-time updates unless you use Lambda Functions, creating more vendor lock-in. It does not support mobile clients by default, but you can use AWS Amplify Datastore instead, which is built on DynamoDB and is designed for not needing a back end.

Amazon Aurora Serverless is fairly flexible because it supports MySQL and PostgreSQL. This means that you can have all of the querying power of one of those databases. Plus, since they are open source, with multiple service providers for them, you can switch easily if needed. Aurora serverless’s one weakness in flexibility is that it does not support mobile or web clients.

Azure CosmosDB excels in this metric. It even supports multiple different databases, like Cassandra, MongoDB, SQL, and more. Because those databases are also open source, it is easy to migrate to another service provider if needed without switching databases. It also does support real-time update feeds through Azure Functions. One of its weaknesses in flexibility though is it does not support web and mobile clients and requires a backend. Overall, it is one of the most flexible serverless databases there are.

Fauna also does pretty well on this metric, except for it being portable between providers. It currently supports using FQL, its own SQL-like language, and GraphQL. It also has built-in support for accessing the database securely from a mobile device and beta support for streaming updates. Its one disadvantage is that the database behind it is proprietary, so it is harder to migrate to another database if needed.

There is a large number of differences between the different databases here. Some, like Aurora Serverless, Cosmos, and Fauna, are better at more advanced querying. Others, like DynamoDB and Firestore, are more focused on other metrics.

Scoring:

Cloud Firestore: 3

Amazon DynamoDB: 3

Amazon Aurora Serverless: 4

Azure CosmosDB: 4

Fauna: 4.5

Ease of use

Cloud Firestore really excels here. You can get started for free on the firebase or google cloud dashboard, and there are SDKs for most platforms, including mobile and web. The pricing is simple, and it will feel very easy to use for new users. It feels more like a complicated object in the cloud than a database.

Amazon DynamoDB does very well, although not as well as Firestore. Its querying is almost as simple, and it has a good free tier to get started with. However, I found it to be slightly harder than Firestore for beginners, although both are easy to pick up.

Amazon Aurora Serverless is pretty easy to set up and use. Unfortunately, it does not have a free tier, so you have to pay to try it, but the dashboard makes it easy to start. Aurora Serverless uses SQL, so it might be harder than a simple NoSQL database if you are a beginner, but it should feel familiar to anyone who uses SQL.

Azure CosmosDB is very easy to use because there are many different APIs supported. You can use any of the databases supported, from SQL to Cassandra to MongoDB, and there are quickstarts for multiple frameworks in each. It is also easy to set up. There is a free tier, and the quickstarts provide everything you need to get started.

Fauna is easy to use for beginners and former SQL users. It supports a query language like SQL, with tutorials for SQL users. It also is easy to use if you are a beginner. Additionally, it has a great dashboard and a simple, free way to get started.

All of the databases listed here abstract away most database management work needed and scale automatically, so none of them should be that hard. If you are a complete beginner, Cloud Firestore or DynamoDB would be the easiest databases to use. Fauna is also pretty easy for beginners. If you have experience with SQL, Aurora Serverless, CosmosDB, and Fauna will feel the most familiar. Aurora Serverless and CosmosDB directly support SQL APIs, and Fauna’s FQL is closer to SQL than most NoSQL databases. In terms of ease to start, all should be super easy. If you are looking to test databases out with a free tier, all except Aurora Serverless have a free tier.

Scoring:

Cloud Firestore: 5

Amazon DynamoDB: 5

Amazon Aurora Serverless: 4

Azure CosmosDB: 4.5

Fauna: 5

Scalability

Cloud Firestore can scale easily. It can scale to zero and scale up easily. You are not even priced for when it is scaling down, as it is priced in reads and writes. The biggest problem with Firestore’s scalability is it is harder to horizontally scale and cannot have separate machines across different regions.

Amazon DynamoDB is similar in scalability to Cloud Firestore. You can choose to use provisioned, or on-demand auto-scaling. It is built the same way and can scale just as well as Firestore. Additionally, it supports multiple regions through Global Tables.

Amazon Aurora Serverless is fairly scalable, although not as much as DynamoDB and Firestore. It scales in APUs, or Aurora Capacity Units, each of which has one VCPU and 2 GBs of RAM. It will increase the total APUs for your database if the CPU usage is over 70% or 90% of connections are being used. If database traffic decreases later, Aurora Serverless will automatically scale down after a cooldown period. Aurora Serverless also supports some cross-region replication. (Note: Some of this only applies to Aurora Serverless v2, which is in preview at the time of this writing).

Azure CosmosDB is also fairly scalable. It automatically scales across regions that you choose, and you can choose whether to use it provisioned or use automatic scaling. The automatic scaling has almost no delay, although the database cannot scale down to zero, instead only scaling down to a tenth of the maximum reads-per-second. The maximum-reads-per-second is configurable.

Fauna, because it was built for applications with unknown loads, can scale well. It uses the Calvin protocol to enable distributed databases, which is more reliable than traditional replication because it replicates what is done instead of the data itself. This allows Fauna to be extremely scalable.

DynamoDB and Fauna win this one, although CosmosDB and Firestore were close. Because of Amazon Aurora Serverless’ APU model, it lost this one, although all databases did well. Overall, you could go with any of these and it would most likely be scalable enough.

Scoring:

Cloud Firestore: 4.5

Amazon DynamoDB: 5

Amazon Aurora Serverless: 4

Azure CosmosDB: 4.5

Fauna: 5

Cost

Cloud Firestore is one of the cheapest databases there is. It charges $0.036 for 100,000 reads and $0.108 for 100,000 writes. Additionally, it has a generous free tier, and only charges $0.108 per GB/Month. Its pricing rises if you choose a multi-region location, but that is mainly for applications that need very high uptime guarantees.

Amazon DynamoDB is almost, but not quite as cheap as Firestore. Its reads are cheaper, at $0.25 per million reads. However, its writes and data storage costs are larger, at $1.125 per million writes and $0.25 per GB/Month. You can potentially decrease costs by using provisioned capacity, which is billed by the hour, and decrease it even more by reserving that capacity for a long period.

Amazon Aurora Serverless is priced differently than the first two databases, using APU/Hour instead of reads and writes. Aurora Serverless v2 is priced at $0.12 APU/Hour. Aurora also makes you pay for storage at $0.11 GB/Month and total requests at $0.22 per million requests.

Azure CosmosDB is similar in pricing to Cloud Firestore and DynamoDB. The serverless offering is based on the same read/write pricing, although it is a bit more complicated. There are two types of data storage, transactional and analytical, but we will focus on transactional here. It is priced at $0.05 per 10,000 writes, and $.005 per 10,000 reads. It also costs $0.282 per million requests, whether reads or writes. Data storage is priced at $0.25 GB/Month.

Fauna’s pricing is simple, and it can be cheap or expensive than DynamoDB and Firestore, depending on what you use. Its reads are priced at $0.50 per million and its writes are $2.50 per million. Additionally, you have to pay for operations done on the Fauna servers, which costs $2.25 per million operations. The place where Fauna can be cheaper is when you are doing more advanced querying because Firestore and DynamoDB can be very expensive to query. Data storage is $0.25 GB/Month.

This is one of the areas with the biggest variation. DynamoDB, Firestore, Fauna, and CosmosDB all abstract the actual machine resources being used, where Aurora Serverless is priced on the actual resources used as APUs. CosmosDB, DynamoDB, and Aurora Serverless are all flexible, allowing you to provision capacity to make things potentially cheaper, depending on how stable your load is. CosmosDB can be expensive, although you can use provisioned capacity to reduce costs. FaunaDB can also be expensive, although its cheap querying and replication can also make it cheaper depending on how you use it.

Scoring:

Cloud Firestore: 5

Amazon DynamoDB: 5

Amazon Aurora Serverless: 4

Azure CosmosDB: 4

Fauna: 4

Conclusion

All of these databases are great choices for the serverless world, it just depends on what type of database you want. If you are looking for more traditional SQL databases, Amazon Aurora Serverless or CosmosDB are great choices. If you are looking for a simple, cheap NoSQL database, and do not need complex querying, Firestore or DynamoDB would work well. Finally, if you want the power of SQL with a more modern API, Fauna might be a good choice. I hope you have learned something and enjoyed reading this!

Final Scores:

Cloud Firestore: 17.5/20

Amazon DynamoDB: 18/20

Amazon Aurora Serverless: 16/20

Azure CosmosDB: 17/20

Fauna: 18.5/20

More content at plainenglish.io

--

--