Skip to content
AI-powered appsNewChat, vision, voice, generationBookings & schedulingAppointments that book themselvesShops & sellingA storefront in every pocketClient & businessRun the operation from one placeCommunities & clubsA home that is not a group chat
Health & wellnessHabits, tracking and calmGames2D, 3D and multiplayerPersonal & toolsThe tool you wish existedInternal toolsThe tool ops never had time for
See all use cases
ArcadeNewPricingSecurity
EngineThe game engine and World EditorHow it worksFrom one sentence to a live productDocsGuides for building and publishingBlogStories, guides and newsChangelogWhat shipped latelyStatusUptime of every serviceSupportGet help from the team
AI-powered appsBookings & schedulingShops & sellingClient & businessCommunities & clubsHealth & wellnessGamesPersonal & toolsInternal tools
See all use cases
ArcadeNewPricingSecurity
EngineHow it worksDocsBlogChangelogStatusSupport
Language
Blog
BackendNovember 22, 20266 min read

Serverless and Edge Functions Explained

A serverless function is code that wakes up when called, does one job on a server, and goes back to sleep. Here is when to use one and how to keep it safe.

Startbase Team
Editorial ink illustration of small brass vending machines on street corners, one dispensing a wrapped parcel from its chute, the parcel in ember orange

Key takeaways

  • Serverless functions are small pieces of server code that run only when called. You pay for runs, not for an idle machine, and the platform handles servers and scaling.
  • Use one for anything that needs a secret key, must be trusted, or reacts to another service: payments, AI calls, webhooks, validation.
  • Functions are short-lived. Long jobs belong in queues or scheduled jobs, and each run must check who is calling.

A serverless function is a small piece of backend code that runs only when something calls it, then stops. You write the function (for example, "create a Stripe checkout for this cart"), upload it, and the platform gives it an address. There are still servers, you just never manage them. An edge function is a serverless function that runs on infrastructure spread across many regions, so it starts close to the user. For most app builders the difference is small; the important part is that this code runs on a server, out of the user's reach.

The vending machine model

A traditional server is a shop with staff on shift all day, whether or not customers come in. A serverless function is a vending machine: nothing happens until someone presses a button, then it does exactly one thing and goes quiet. Ten thousand people pressing at once? The platform rolls out more machines. Nobody for a week? You pay little or nothing.

The trade-off follows from the model. A vending machine does not remember the last customer, cannot run for hours, and takes a moment to wake if it has been idle. Those are the three rules of serverless: stateless, short, and sometimes cold.

Five jobs that belong in a function

Everything in your app's frontend can be read and changed by anyone using it. So the test is simple: if a job needs a secret, needs to be trusted, or needs to happen when no browser is open, it goes in a function.

  1. 01Calling a paid API with a secret key. An AI summary, an SMS, a map geocode. The key stays in the function; the browser only sees the result.
  2. 02Starting a payment. The function looks up real prices from the database and creates the checkout. A browser that says "this costs $1" is ignored.
  3. 03Receiving webhooks. Stripe, email providers and other services post events to a function's address. The function verifies the signature and updates your data.
  4. 04Validating and enforcing rules. "A user can create at most three free projects" or "a booking cannot overlap another" is checked server-side, where it cannot be skipped.
  5. 05Sending email. A welcome message on signup or a receipt after a purchase, using an email service key the browser never sees.

Tip

Simple reads and writes of your own data usually do not need a function. With row level security, the app can talk to the database directly and the database enforces who sees what.

What a function actually does

Take a function called `create-checkout` in a print shop app. Each time it is called, it runs these steps:

  1. 01Read the request: `{ "items": [{ "poster_id": 14, "size": "A2", "qty": 2 }] }` plus the caller's session token.
  2. 02Verify the token. No valid user, answer 401 and stop.
  3. 03Look up poster 14's A2 price in the database, ignoring any price the browser sent.
  4. 04Read `STRIPE_SECRET_KEY` from the environment and ask Stripe for a checkout session.
  5. 05Return the checkout address. The browser redirects the shopper there.

Every function you write should start with the same two moves: check who is calling and check what they sent. The function is public on the internet the moment it has an address, so "only my app calls it" is not a security plan.

Cold starts, timeouts and limits

  • Cold starts: a function that has not run recently needs a moment to load before answering. Edge platforms keep this short, but the first call after a quiet period can be noticeably slower than the rest.
  • Timeouts: functions have a maximum run time, typically measured in seconds to a few minutes depending on the platform and plan. Generating a long video or processing a huge file does not fit; hand it to a job queue or a scheduled job instead.
  • No memory between runs: a counter kept in a variable resets. Anything that must persist goes in the database or storage.
  • Cost per run: cheap individually, but a function called in a loop on every keystroke adds up. Debounce, cache and rate-limit.

When a function fails

Functions fail in a handful of predictable ways, and the error message usually says which one:

  • 401 or 403: the caller was not signed in, the session expired, or the function requires sign-in and the app did not send the token.
  • 500 with "undefined" in the log: very often a missing secret. The function tried to read `STRIPE_SECRET_KEY` and got nothing because it was never saved, or was saved under a slightly different name.
  • A CORS error in the browser console: browsers block a page from calling a server on another address unless that server answers with headers allowing it. The function needs to return those headers, including for the browser's preliminary OPTIONS request.
  • A timeout: the function waited too long on another service. Add a time limit to outside calls and return a friendly error instead of hanging.
  • It works in the preview, not in production: different secrets, different allowed addresses, or a function that was changed but not redeployed.

Read the function's own logs first, not just the app's error. The app sees "something went wrong"; the log sees the line that broke.

When a regular server is better

Serverless suits request-and-response work: something asks, the function answers. It is a poor fit for work that runs continuously, like a game server holding a match in memory, a bot that keeps a connection open, or a worker crunching a queue all day. Those need a long-running process. On Startbase, multiplayer games with action gameplay use a dedicated room server per match for exactly this reason, while lobbies, presence and turn-based play run on the backend's realtime channels. See realtime features explained.

Edge functions in a Startbase app

Startbase Cloud includes Supabase edge functions: server-side TypeScript functions for calling third-party APIs with secret keys, webhook handlers, payment logic and input validation. The usual path is to describe what you want in chat and let the agent write and deploy the function from your workspace. The Edge Functions section in the Backend tab lists each function with invocation counts, success rate and average duration. Open one to see its version, whether it requires sign-in or is public, its code, an invocation chart with errors marked, recent logs and a Copy URL button. Invoke sends a test ping and shows the JSON reply. Details in the edge functions docs.

Functions read keys from Backend → Secrets as environment variables, which are never exposed to client-side code (API keys and secrets covers why). When something fails, Backend → Logs filters to the function runtime, and each error row has a Fix with AI button that hands the event to the agent.

Add an edge function called moderate-listing to my marketplace. When a seller submits a listing, the function checks they are signed in, rejects titles over 80 characters or prices below $1, sends the description to the moderation step, and only then saves the listing as "live". Store the API key in Secrets. Return a clear error message the form can show next to the field that failed.

Notice the brief puts validation in the function, not only in the form. Forms are for helpful messages; functions are for rules. If your app is still frontend only, start with what a backend is.

Frequently asked questions

What does serverless mean if there are still servers?

It means you do not manage them. The platform runs your function on its servers when called, scales it up and down, and bills you per run instead of for a machine that sits idle.

What is the difference between an edge function and a serverless function?

An edge function is a serverless function that runs on infrastructure distributed across many locations, closer to users. The programming model is the same: short, stateless code triggered by a request.

Can an edge function run a long task?

Not reliably. Functions have time limits. Break long work into steps, use a scheduled job, or move it to a long-running worker.

Is my edge function code public?

No. Users can call its address, but they cannot read its code or the secrets it uses. That is exactly why secret keys and trusted rules belong there.

On this page

  • The vending machine model
  • Five jobs that belong in a function
  • What a function actually does
  • Cold starts, timeouts and limits
  • When a function fails
  • When a regular server is better
  • Edge functions in a Startbase app

Keep reading

More in Backend
Editorial ink illustration of a shop counter with a brass cash register and a curling paper receipt, the receipt in ember orange
BackendNovember 22, 2026

How to Accept Payments in Your App with Stripe

Taking money online is mostly a solved problem, if you let Stripe hold the card and you trust only its webhook. Here is the flow, the data you store and the mistakes to avoid.

5 min read
Editorial ink illustration of an iron safe set into a workshop wall with a key hanging on a hook beside it, the key in ember orange
BackendNovember 22, 2026

API Keys and Secrets: Keeping Them Safe

Anything you ship to a browser or phone can be read. Here is how to tell a public key from a secret one, where secrets belong, and the five-step plan for a leaked key.

5 min read

Read less. Ship more.

Everything in this post is one prompt away. Describe your app and watch it build.

Start building

Apps, games, backends and publishing from one conversation.

Product

  • Features
  • Use cases
  • Pricing
  • Changelog

Resources

  • Blog
  • Docs
  • Support
  • Status
  • Security

Contact

  • w@startbase.ai
  • X / Twitter
  • LinkedIn
  • Instagram

Legal

  • Terms
  • Privacy

© 2026 Startbase. All rights reserved.