Serverless Handbook

Student Login

Where and how to store data

Serverless systems don't have a hard drive, where does your data go? You need a database.

But how do you choose which database and where do you put it? It depends.

Every database has advantages and disadvantages. Always fit your tech to your problem, not your problem to your tech.

First, what is a database? It's a system for storing and organizing data.

A database is an organized collection of data, generally stored and accessed electronically from a computer system.

Every database technology gives you these features:

  • keeps your data
  • lets you query data
  • lets you update data

Keeping data is the difference between a cache and a database. You can have an in-memory database for speed, but that doesn't make it a cache.

How to choose a database

Databases seek to find a balance between different optimization criteria. Your choice depends on how that balance fits the problem you're solving.

The common criteria are:

  1. Speed of reading data
  2. Speed of writing data
  3. Speed of updating data
  4. Speed of changing the shape of data
  5. Correctness of data
  6. Scalability

Notice how the list is about speed? That's because speed of data access is the biggest predictor of app performance.

I've seen API endpoints hit the database 30+ times. Queries that take 10ms instead of 1ms can mean the difference between a great user experience and a broken app.

ACID – a database correctness model

We'll focus on speed in this chapter. But to gain speed and scalability, databases sacrifice correctness. It's important that you know what correctness means in a database context.

Traditional databases follow the ACID model of transactional correctness. A transaction being a logical operation on your data.

  • Atomicity ensures that operations inside a transaction succeed or fail together and aren't visible until they all succeed
  • Consistency ensures your data is in a valid state and doesn't become corrupted by a half-failed transaction
  • Isolation ensures transactions executed in parallel behave the same as if they happened one after another
  • Durability ensures that once a transaction succeeds, it stays succeeded and the data doesn't vanish

Certain databases add additional levels of logical correctness on top of the ACID model. We'll talk about those later.

Hello! 👋

Are you a frontend engineer diving into backend? Do you have just that one bit of code that can't run in the browser? Something that deals with secrets and APIs?

That's what cloud functions are for my friend. You take a JavaScript function, run it on serverless, get a URL, and voila.

But that's easy mode. Any tutorial can teach you that.

What happens when you wanna build a real backend? When you want to understand what's going on? Have opinions on REST vs GraphQL, NoSQL vs. SQL, databases, queues, talk about performance, cost, data processing, deployment strategies, developer experience?

🤯

Unlock your free chapter!

Access to this chapter immediately, extra free chapter and Serverless crash course in your email ✌️

I like privacy too. No spam, no selling your data.


buy now amazon

Dive into modern backend. Understand any backend

Serverless Handbook shows you how with 360 pages for people like you getting into backend programming.

With digital + paperback content Serverless Handbook has been more than 1 year in development. Lessons learned from 14 years of building production grade websites and webapps.

With Serverless Handbook, Swiz teaches the truths of distributed systems – things will fail – but he also gives you insight on how to architect projects using reliability and resilience perspectives so you can monitor and recover.

~ Thai Wood, author of Resilience Roundup

If you want to understand backends, grok serverless, or just get a feel for modern backend development, this is the book for you.

Serverless Handbook full of color illustrations, code you can try, and insights you can learn. But it's not a cookbook and it's not a tutorial.

Serverless Handbook on your bookshelf
Serverless Handbook on your bookshelf

Yes, there's a couple tutorials to get you started, to show you how it fits together, but the focus is on high-level concepts.

Ideas, tactics, and mindsets that you need. Because every project is different.

The Serverless Handbook takes you from your very first cloud function to modern backend mastery. In the words of an early reader:

Serverless Handbook taught me high-leveled topics. I don't like recipe courses and these chapters helped me to feel like I'm not a total noob anymore.

The hand-drawn diagrams and high-leveled descriptions gave me the feeling that I don't have any critical "knowledge gaps" anymore.

~ Marek C, engineer

If you can JavaScript, you can backend.

Plus it looks great on your bookshelf 😉

buy now amazon

Cheers,
~Swizec

Previous:
Robust backend design
Next:
Creating a REST API
Created bySwizecwith ❤️