Technology / System Admin

Which Database Should You Use With a Serverless App?

How do I Choose a database for a serverless app
Follow us
Published on September 15, 2022

You did it! You found the next big app idea. You’re only a year out from creating a unicorn, but you haven’t figured out how to store data for your app yet. You’ve heard about this cool new thing called serverless computing, and you decided you want to use AWS Lambda and AWS API gateway to create your serverless app. 

That still doesn’t solve how you store customers’ information, though. You might find yourself asking, “How do I choose a database for a serverless app?” So, today, we are going to answer that.

What is a Serverless Database?

A serverless database is a database hosted and managed by a third-party provider. These providers include AWS, Google Cloud Compute, and Microsoft Azure services. Serverless databases are also colloquially called managed databases. 

Traditionally, a database would be hosted on internal hardware. However, we must be careful with how we phrase that. A database doesn’t need to be hosted on a server (though it often is) or within an operating system like Windows. 

For example, a popular media application called Plex uses a SQLite database. SQLite is a self-managed database that is stored as a file. With traditional databases, an application or service would communicate with a database controller.

That database controller includes drivers that interpret DB calls from apps with the database itself. That database controller is part of the (Plex) app with SQLite. This kind of database has the benefit of being extremely portable, too. 

Nonetheless, an operator or application hosts and directly maintains that database. That’s the common thread here. DB admins build, support, and host databases for services and applications. It would be like your mechanic building and maintaining your car for you.

However, a serverless database, or a managed database, is hosted and maintained by another provider. The maintenance and hosting of the database are abstracted away from the app and operator. Regarding serverless databases, applications only need to call an API to store or retrieve data. Many serverless database products also allow applications and services to connect directly to those managed databases. 

What Types of Databases Does AWS Offer?

AWS offers eight different types of serverless databases. Those database types include:

  • Relational

  • Key-Value

  • In-Memory

  • Document

  • Wide-Column

  • Graph

  • Time Series

  • Ledger

If you are already familiar with the world of databases, you should recognize at least a few of those database types. The most widely used database types are relational and document types. 

An example of a relational database would be MySQL or Postgres. A relational database is similar to an Excel spreadsheet in which rows and columns organize each table in the database. Data stored in those rows and columns is highly structured. Likewise, data between tables or spreadsheets can correlate somehow. AWS calls its relational database services Aurora, RDS, and RedShift

The other more popular database type is a document database. NoSQL is a term typically used to describe these types of databases. A popular version of a NoSQL or Document database is Mongo. Document databases store records in tables that look like JSON objects with common data. However, each entry in a document database may not have the same type of data or all of the same data as a relational database. Likewise, data stored between tables may have nothing in common whatsoever. 

A third popular database is Redis. Though Redis can store long-term data, it typically isn't. Redis lives in memory, which makes it insanely fast. Because of this, Redis is generally used as a caching layer between applications and databases. Amazon’s version of Redis is called Elistacache or MemoryDB for Redis. 

What are the Benefits of Using a Managed DB Provider?

One of the most challenging aspects of hosting any service or application is its upkeep. This is why many software engineers and in-house IT departments are turning to serverless applications. 

Hosting a database or any application is hard work. First, databases need to be designed and architected. All college degrees are devoted to this step alone. 

Then, that database needs to be deployed and secured. Securing databases is difficult today. Databases are primary targets for cybercriminals. They need to be under lock and key. That includes heavily sanitizing inputs and creating proper security permissions. 

Finally, databases need to be updated. That means applying patches that involve planning downtime and maintenance. If your database is set up for high availability or redundancy, those updates and changes must be synced across all DB nodes. 

We haven’t even gotten to creating an application yet.

Typically, organizations hire a dedicated person, if not an entire team, solely to manage databases. This team isn’t even responsible for building and maintaining apps or the IT infrastructure. Their primary purpose is only to manage databases. 

Serverless databases offload this work to a service provider. For instance, AWS will take care of this for you. The same is true for Google Cloud, Azure, and even Atlass. 

So, what are the benefits of using a serverless database? You get to keep your sanity (Eg, reduced downtime, seamless maintenance periods, better security, etc…).

Of course, a serverless database is not the appropriate answer for everyone. Likewise, a serverless database may be impossible due to laws and regulations depending on your industry. Furthermore, a serverless database may cost you more in the long run. 

Before launching or migrating your application or service, you must consider the pros and cons of using a serverless database versus a self-hosted solution. 

How to Choose a Database for a Serverless App

We’ve discussed databases a lot so far. You should feel comfortable with the differences between the types of serverless databases that AWS offers. If you need more help, check out CBT Nugget’s skill course on choosing the right datastore for AWS for your apps. 

Here’s the tl;dr version, however. 

You probably already know if you must use a wide-column, graph, or time-series database. Those types of databases are typically used under specific scenarios. 

Instead, you’ll likely need to decide between using a relational or document-type database. There are a lot of pros and cons and theories as to why you should use one type of database over another. As I stated, though, this is the tl;dr version. So, here’s the advice I was given years ago (and it makes sense).

Do you have a good idea of what kind of data you need to collect and what kind of data you will need in the future, and already have a good roadmap planned for your app? If this describes you, a relational database is the best option. In that case, look at AWS Aurora or RDS.

Do you have a general idea of what kind of data you need to collect but are unsure? Have you only gotten as far as planning the MVP for your app? In that case, go with a document-style database. They are much more lenient and versatile at the cost of a bit of performance. In this case, take a look at Amazon DocumentDB.

Final Thoughts

By now, you should have a comfortable understanding of choosing a database for a serverless app. We hope you understand what types of products AWS offers for serverless databases. However, this article is not an exhaustive resource on those databases. It’s merely a primer. That means you may want to spend more time understanding how serverless databases work in AWS and how to communicate with them.

That’s where CBT Nuggets comes in. If you know that you will most likely need a serverless relational database, we have covered it for you. CBT Nuggets has online courses for Amazon RDS. 

Is a document database the right tool for your job? Easy enough. Learn how to build a MERN application with CBT Nuggets, too. 

If, after you read this article, you decide that a serverless database isn’t what you need, then CBT Nuggets has MySQL training classes. Learn how to design, manage, and deploy SQL databases like a pro.

Don't miss out!Get great content
delivered to your inbox.

By submitting this form you agree to receive marketing emails from CBT Nuggets and that you have read, understood and are able to consent to our privacy policy.

Recommended Articles

Get CBT Nuggets IT training news and resources

I have read and understood the privacy policy and am able to consent to it.

© 2024 CBT Nuggets. All rights reserved.Terms | Privacy Policy | Accessibility | Sitemap | 2850 Crescent Avenue, Eugene, OR 97408 | 541-284-5522