What is Serverless function?
A piece of server code that starts for each request and stops soon after. You pay per use, and it has time and size limits.
Where Serverless function goes wrong in real apps
Each of these is a short scenario built from a real failure in an app made with AI. Read the answer here, or walk through it yourself in about four minutes.
Launch day · 4 minutes · Pro
Every page spins forever
Your post goes viral. Within minutes every page spins, then fails. Your database dashboard says CPU is nearly idle.
Read the fixWhy does my app hang with too many connections?
Each copy of a serverless function opens its own database connections, and a traffic spike runs many copies at once, so the database hits its connection limit and refuses new ones. Connect through your database's connection pooler, which shares a few connections across many requests.
Launch day · 4 minutes · Pro
The reminder that never came
Your app promises 'We'll remind you in 24 hours'. Nobody has ever received the reminder.
Read the fixWhy doesn't setTimeout work in my serverless API?
Serverless functions run for one request and stop shortly after responding, so timers scheduled inside them never fire. Store future work as data with a due time, and process it with a scheduled job (cron) or a queue that retries failures. Check your plan's cron frequency limits.
AI inside your app · 4 minutes · Pro
Another customer's document
Your 'chat with your documents' app answered a question by quoting a contract. The user has never uploaded a contract. Another customer has.
Read the fixHow do I keep RAG data separate per user?
Filter by user or team inside the search itself, before results reach the model. Similarity search returns the closest chunks from everything it can see, so an unfiltered query mixes customers. In Supabase, avoid security definer match functions that skip RLS, use security invoker, filter by owner, and test with two accounts.
Bills that explode · 4 minutes · Pro
The update that updates itself
You added a function that stamps 'updated_at' whenever a profile changes. By morning your database bill has a new digit.
Read the fixWhy is my cloud function looping forever?
The function writes to the same document or row that triggers it, so each write starts another run. Add a guard that skips the write when nothing meaningful changed, and remember that budget alerts only send emails; they do not stop spending unless you add a hard cap.
Launch day · 4 minutes · Pro
The upload that was too big
Users can upload photos to their listings. Phone photos fail with '413 Payload Too Large'. Screenshots work fine.
Read the fixHow do I fix 413 Payload Too Large on uploads?
Serverless functions limit how large a request body can be, so large files fail when sent through your API. Have your server create a signed upload URL after checking the user, then let the browser upload directly to storage. Enforce file type and size limits on the storage bucket itself.
Launch day · 4 minutes · Pro
The 504 at second 60
Generating a long AI report works on your laptop. In production, where the route's time limit is set to 60 seconds, big reports fail with '504 Gateway Timeout'.
Read the fixWhy do I get a 504 timeout only in production?
Hosted serverless functions stop at a set time limit, while your laptop has none. Long AI calls, imports or file processing exceed it and return 504 Gateway Timeout. Streaming improves the wait but still counts toward the limit; move long tasks to a background job that reports progress.
Related terms
- Request
- A message your browser (or any program) sends to a server asking for something: 'give me invoice 105' or 'save this profile'.
- API
- The part of an app that other programs talk to. Your app's pages ask its API for data, like a waiter taking orders to a kitchen.
- Server
- A computer that runs your app's code out of sight. Users can't change what happens there, which is why checks belong there.
- Table, row, column
- A table is like one spreadsheet (orders). Each row is one item (one order); each column is one detail (price, date).
- Endpoint
- One specific address on your server that does one job, like /api/invoices. Each one needs its own safety checks.
- Browser
- Chrome, Safari and friends. Everything that runs here is visible to, and changeable by, the person using it.