AutoMerge is generally available

Last updated:

What Is Framework-Defined Infrastructure?

Say you want to send customers an email after they place an order, and your service runs on AWS. The application change is small: publish an event when the order is saved, and handle that event somewhere else. Then the infrastructure work starts. You write a queue in Terraform, an IAM policy that lets the service publish to it, a second policy that lets the worker consume from it, and a variable that tells the service where the queue lives. The application change and the infrastructure change sit in different files, often in different repositories, and they have to ship in the right order.

Framework-defined infrastructure removes the second half of that work. You write the feature in the framework's terms, and a build step reads your code and works out that it needs a queue, a consumer, and permissions between them. Vercel, which coined the term, describes it as "an evolution of IaC, where the deployment environment automatically provisions infrastructure derived from the framework".

From infrastructure as code to framework-defined infrastructure

Infrastructure as code (IaC) made infrastructure reviewable. Instead of clicking through a cloud console, you describe resources in Terraform's HCL or, with Pulumi and the AWS CDK, in TypeScript, Python, or Go. The description lives in version control, and a tool makes the cloud match it.

IaC doesn't change who does the describing. With Pulumi you write TypeScript, but you still write new aws.sqs.Queue(...). You describe resources, and you keep that description in step with the application that uses them. The application says "publish an order event". A separate file says "there is a queue, and this role may send to it". Usually nothing checks that the two agree until something fails in a running environment.

Framework-defined infrastructure relies on inversion of control. The framework owns the structure of your application: where routes live, how handlers are declared, and how a service reaches a database or a topic. Because that structure is predictable, a program can read it at build time and derive the infrastructure from it. The application code becomes the only description of what the system needs.

Here is what that looks like with Next.js. These two files are a complete feature: a product page with a photo, and an endpoint that accepts orders.

tsx
// app/products/page.tsx
import Image from "next/image";
import sneaker from "./sneaker.jpg";

export default function ProductsPage() {
  return <Image src={sneaker} alt="Red running sneaker" />;
}

// app/api/orders/route.ts
export async function POST(request: Request) {
  const order = await saveOrder(await request.json());
  return Response.json(order, { status: 201 });
}

Nothing in this code names a function, a CDN, or an image service. To run it on AWS with infrastructure as code, you write and maintain those resources yourself. On Vercel, the build step derives them from the code:

Before and afterRunning the Next.js code above8 resources → 0

The two Next.js files above, run two ways. Before, with infrastructure as code on AWS, you write the two files plus 8 Terraform resources: an S3 bucket and a CloudFront distribution to serve the products page, a Lambda function and a CloudFront cache policy to resize the photo, and a Lambda function, an IAM role, an API Gateway API, and a route to handle orders. After, with framework-defined infrastructure, you write only the two files, and the build step derives a prerendered page on the CDN, image optimization, and a serverless function with its route.

With IaC, the application code and the infrastructure definitions are two descriptions of one system, and a person writes and syncs both. With framework-defined infrastructure there is one description, and the build step derives the resources from it. The two can't disagree, because the resources come from the same code that uses them.

Framework-defined infrastructure doesn't make Terraform go away. Networks, cloud accounts, shared databases, and anything outside the application still need a description somewhere. The framework takes over the resources that belong to one application.

Examples: Vercel and Encore

Several platforms derive infrastructure from application code. Vercel and Encore are two of them, and they work at different layers. Vercel infers infrastructure from how you use a web framework. Encore infers it from backend primitives that you declare in your code.

Vercel

Vercel derives infrastructure from Next.js and other web frameworks without any infrastructure declarations in your code. In the words of Vercel's documentation: "Your framework code defines which routes are static, cacheable, or dynamic." Here are more Next.js features and what Vercel turns them into:

Build stepNext.js features on VercelBuilding 0/5

An animation of a Vercel build reading Next.js code and deriving infrastructure from it, one feature at a time. A page without request data becomes static HTML on the CDN. An Image component that renders sneaker.jpg becomes image optimization, which resizes the photo for each device and caches the result. A page that reads cookies becomes a function that renders per request. generateStaticParams becomes one prebuilt page per parameter. A revalidate export of 3600 seconds becomes a cached page: once it is older than an hour, the next request still gets the cached copy while Vercel regenerates the page in the background.

Frameworks compile these decisions into the Build Output API, a file format that Vercel reads to provision production. Any framework that produces this format deploys the same way. Each commit gets its own deployment with its own infrastructure, so the preview of a pull request runs on the same kind of resources as production.

Encore

Encore works on the backend. You declare infrastructure in your application code, but as application concepts such as an API endpoint, a database, or a topic, rather than as cloud resources. This is the order endpoint from the start of this article, with no Terraform:

ts
import { api } from "encore.dev/api";
import { SQLDatabase } from "encore.dev/storage/sqldb";
import { Topic } from "encore.dev/pubsub";

// Becomes a Postgres database: a local container in development,
// RDS on AWS, or Cloud SQL on Google Cloud.
const db = new SQLDatabase("orders", { migrations: "./migrations" });

// Becomes a topic: a local broker in development, SNS and SQS on AWS,
// or Pub/Sub on Google Cloud.
export const orderPlaced = new Topic<{ orderID: number }>("order-placed", {
  deliveryGuarantee: "at-least-once",
});

// Becomes a public endpoint at POST /orders, with permission to use
// the database and to publish to the topic.
export const placeOrder = api(
  { expose: true, method: "POST", path: "/orders" },
  async ({ sku }: { sku: string }) => {
    const order = await db.queryRow`INSERT INTO orders (sku) VALUES (${sku}) RETURNING id`;
    await orderPlaced.publish({ orderID: order!.id });
  },
);

Encore parses these declarations without running the code and builds an application model of which services exist and which endpoints, databases, and topics each of them uses. The code says what exists and how it connects. The platform team decides how it runs in each environment, including instance sizes, regions, and networking.

Pros and cons

Both approaches give the platform a complete picture of the application before it runs. That picture is where the advantages come from, and most of the disadvantages too.

ProsCons
AI coding agentsAn agent changes application code and nothing else. Encore fails the build on invalid declarations, the whole stack runs locally, and every pull request gets a preview environment that automated checks can validate against.When a task needs infrastructure the framework doesn't model, the agent is back to writing IaC.
ObservabilityThe framework instruments every boundary the same way. Next.js creates OpenTelemetry spans out of the box, and Encore traces API calls and database queries without instrumentation code. Encore also generates an architecture diagram from the application model, before any traffic arrives.Built-in instrumentation covers boundaries, not business context such as which customer placed an order. You add that yourself.
DriftResources come from the code that uses them, so code and infrastructure can't disagree.Someone can still change a resource in the cloud console, and the platform has to detect it.
ReviewOne pull request carries the feature and its infrastructure.What runs in production is the output of a build step, so you need to know what the framework derived and why.
ControlPermissions follow from usage, and every pull request can get its own environment.You get the settings the framework exposes. Anything else needs an escape hatch, usually IaC.
PortabilityEncore deploys the same code to AWS or Google Cloud.Your code depends on the framework, and often on its platform. Leaving means writing the infrastructure it used to derive for you.
Code styleConventions are well documented and familiar to coding agents.Static analysis needs predictable code. Encore requires literal resource names and module-level declarations.

Summary

Framework-defined infrastructure moves the interface to the cloud up a level, from resources to application concepts. Coding agents work at that level, and so does the telemetry that is most useful to read, which is why I expect more stacks to move in this direction. The price is control. The more the framework derives, the more you depend on it deriving the right thing.