# Dynamic IO API (v15)

> Explicitly declaring dynamic boundaries.

Subject: Next.js | Lesson 65 of 65 | 3 min read
Interactive lesson: https://codewithanimation.in/nextjs/dynamic-io
Previous: [Partial Prerendering (PPR)](https://codewithanimation.in/nextjs/partial-prerendering.md)

## The Shift in Caching Defaults

In Next.js 14, every `fetch()` was aggressively cached by default. While fast, this led to widespread confusion when live databases updated but the website didn't.

The experimental **Dynamic IO** flag in Next.js 15 flips this paradigm. It defaults to treating IO (like database queries and headers) as dynamic, requiring you to explicitly opt-in to caching.

## The Connection API

To give developers precise control over where a static build stops and dynamic execution begins, Next.js introduced the `connection()` API.

When the Next.js compiler hits `await connection()` during the build, it immediately stops statically rendering that branch of the React tree and leaves a Suspense boundary for dynamic execution.

## Halting the Build

```typescript
import { connection } from 'next/server';

export default async function Dashboard() {
  // Everything above this line can be statically generated
  
  // Halt static generation here. Wait for a real user request.
  await connection();
  
  // Everything below this line executes dynamically at runtime
  const data = await fetchUserData();
  return <Profile data={data} />;
}
```

## Common mistake: Removing the Blunt Instruments

Previously, if a single component needed fresh data, developers resorted to adding `export const dynamic = 'force-dynamic'` at the top of the route.

This was a blunt instrument that ruined the static performance of the *entire page*. The `connection()` API is a surgical scalpel, allowing granular dynamic boundaries.

## Try it: The Static Halt

Watch how the Next.js compiler sweeps through the code but is physically stopped by the connection boundary.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/nextjs/dynamic-io

## Check yourself

### Question 1

What does calling `await connection()` do during the Next.js build process?

- A. It opens a persistent WebSocket connection to the server.
- B. It forcefully caches the subsequent database queries.
- C. It halts static generation at that exact line, marking everything below it as dynamic.
- D. It connects to the Vercel Edge Network.

Correct answer: C

`await connection()` explicitly tells the compiler: 'Stop statically building here. This data requires a real, active user request to evaluate.'

## Remember this

- Dynamic IO is an experimental flag in Next.js 15 that changes caching defaults.
- It moves away from implicit aggressive caching to explicit granular caching.
- `await connection()` is used to explicitly mark a dynamic IO boundary, halting static generation.
