01 / 02

What are Server Actions and Server functions? How are they different?

Difficulty: 6/10
Server Actions, Server Functions, Next.js data fetching
Server Functions:
  1. 1

    Server Functions allow Client Components to call async functions executed on the server.

  2. 2

    A Server Function can be defined with the React 'use server' directive.

Server Actions:
  1. 1

    Server Actions are asynchronous functions that are executed on the server. They can be called in Server and Client Components to handle form submissions and data mutations in Next.js applications.

  2. 2

    According to react documentation If a Server Function is passed to an action prop or called from inside an action then it is a Server Action

  3. 3

    A Server Action can be defined with the React 'use server' directive.

javascript

Scenario Questions

0-2 years experience

  1. 1You need to submit a contact form without exposing any secret keys. How would you implement this using a Server Action instead of a regular API route?
  2. 2If you add a `use server` directive inside a component that also renders client‑side UI, what happens when the page loads?
  3. 3Explain what occurs when a client component calls a function marked with `use server`. Where does the code run?

2-5 years experience

  1. 1Your team added a Server Action for processing a checkout, but the page refreshes unexpectedly. Walk me through how you'd debug the problem.
  2. 2When refactoring an existing API route into a Server Action, what trade‑offs do you consider regarding caching, error handling, and type safety?
  3. 3Why might a Server Action be unable to read request cookies in a particular request, and how would you work around that?

5-8 years experience

  1. 1Design a strategy for sharing business logic between multiple Server Actions and Server Functions across several pages while keeping the codebase maintainable.
  2. 2At high traffic, how would you monitor the performance and latency of Server Actions compared to traditional API routes? Which metrics matter most?
  3. 3Discuss the implications of using Server Actions for a public API that runs on Vercel edge functions, focusing on cold starts, rate limiting, and edge caching.

8+ years experience

  1. 1Your organization is migrating a monolith to a micro‑frontend architecture with Next.js. How would you decide which pieces become Server Actions versus separate backend services?
  2. 2What long‑term guidelines would you set for teams to choose Server Functions over API routes, especially when multiple squads own different domains?
  3. 3If you need to support both Vercel edge runtimes and on‑premise servers, how would you abstract Server Actions to avoid vendor lock‑in while preserving functionality?

Follow-up Questions

  • What security benefits do Server Actions give you out of the box?
  • How does using a Server Action impact the client bundle size?
  • Can you describe a scenario where you would still prefer a traditional API route?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.