# Performance Implications of Using Agent-Native: SQL Indexes, Action APIs, and Real-Time Sync

> Explore agent-native performance: Discover how indexed SQL tables, unified action APIs, and real-time sync boost speed. Learn about index maintenance for write-heavy loads.

- Repository: [Builder.io/agent-native](https://github.com/BuilderIO/agent-native)
- Tags: performance
- Published: 2026-06-21

---

**Agent-Native delivers high performance through indexed SQL tables, a unified action API that eliminates network hops, and real-time sync with optimistic UI updates, though it requires careful index maintenance for write-heavy workloads.**

The **BuilderIO/agent-native** framework implements a single-source-of-truth architecture where SQL (via Drizzle) stores all application data, actions expose the data surface, and both the agent and UI share the same action-based API. This design creates specific performance characteristics that scale efficiently as data grows, provided you understand how the underlying indexes and network optimizations work.

## SQL-Centric Data Layer with Purpose-Built Indexes

All mutable state in Agent-Native lives in relational tables created and migrated by the framework. The migration scripts add **purpose-built indexes** for every "ownable" table—those scoped by `owner_email` and `org_id`—ensuring that permission-scoped queries remain fast even with large datasets.

### Composite Indexes for Ownable Tables

In [`templates/videos/server/plugins/db.ts`](https://github.com/BuilderIO/agent-native/blob/main/templates/videos/server/plugins/db.ts), the framework creates composite indexes that optimize the most common access patterns. These indexes work on both SQLite (development) and Postgres (production):

```typescript
// v16: performance indexes for ownable list/read access paths
{
  version: 16,
  sql: `CREATE INDEX IF NOT EXISTS compositions_owner_org_updated_idx ON compositions (owner_email, org_id, updated_at);
        CREATE INDEX IF NOT EXISTS design_systems_owner_org_updated_idx ON design_systems (owner_email, org_id, updated_at);
        CREATE INDEX IF NOT EXISTS folders_owner_org_created_idx ON folders (owner_email, org_id, created_at);
        CREATE INDEX IF NOT EXISTS composition_shares_resource_principal_idx ON composition_shares (resource_id, principal_type, principal_id);
        CREATE INDEX IF NOT EXISTS folder_memberships_folder_id_idx ON folder_memberships (folder_id)`,
},

```

These **composite indexes** transform expensive table scans into O(log n) lookups. When [`actions/compositions/list.ts`](https://github.com/BuilderIO/agent-native/blob/main/actions/compositions/list.ts) queries for a user’s compositions, the `accessFilter` automatically injects the `(owner_email, org_id)` condition, hitting the `compositions_owner_org_updated_idx` index directly:

```typescript
// actions/compositions/list.ts
export const listCompositions = defineAction(async ({ db, user }) => {
  const rows = await db
    .select()
    .from(compositions)
    .where(accessFilter(compositions, user))
    .orderBy(compositions.updated_at, "desc");
  return rows;
});

```

### Sharing and Permission Checks

The framework optimizes permission validation through the `*_shares` tables. The `composition_shares_resource_principal_idx` index accelerates `EXISTS` sub-queries used in [`core/provider-api/access.ts`](https://github.com/BuilderIO/agent-native/blob/main/core/provider-api/access.ts):

```typescript
// core/provider-api/access.ts
export const hasShare = async (resourceId, principal) => {
  const exists = await db
    .select()
    .from(composition_shares)
    .where(and(
      eq(composition_shares.resource_id, resourceId),
      eq(composition_shares.principal_type, principal.type),
      eq(composition_shares.principal_id, principal.id)
    ))
    .exists();
  return exists;
};

```

This index allows the database to answer permission checks in microseconds, even when checking access across thousands of shared resources.

## Action-Centric API Architecture

Agent-Native eliminates the traditional "fetch-then-fetch-again" pattern by routing all UI and agent interactions through **server-side actions** defined with `defineAction`. This unified API reduces network latency by performing database queries server-side and returning complete results in a single round-trip.

### Eliminating Network Round-Trips

Instead of separate REST endpoints, components call actions directly. The [`actions/compositions/get.ts`](https://github.com/BuilderIO/agent-native/blob/main/actions/compositions/get.ts) file demonstrates how a single indexed query retrieves data with minimal overhead:

```typescript
// actions/compositions/get.ts
export const getComposition = defineAction(async ({ input, db }) => {
  const comp = await db
    .select()
    .from(compositions)
    .where(and(eq(compositions.id, input.id), accessFilter(compositions)));
  return comp;
});

```

Because both the AI agent and the UI components consume the same action surface, they benefit from identical query optimization and caching strategies. This **shared action layer** prevents the duplication of data-fetching logic that often slows down traditional client-server architectures.

## Real-Time Sync and Optimistic UI

The framework provides built-in **polling sync** via `useDbSync` that monitors the `application_state` table and pushes minimal deltas to connected clients. When a user edits a composition, the client immediately updates its local cache (optimistic UI) while the server persists the change.

The sync implementation in [`client/vite-dev-recovery-script.ts`](https://github.com/BuilderIO/agent-native/blob/main/client/vite-dev-recovery-script.ts) uses lightweight `SELECT` statements against the small `application_state` table, keeping bandwidth overhead minimal. This architecture avoids full page reloads by streaming only changed data to other agents in real-time.

## Modular Mini-Apps for Workload Isolation

Agent-Native encourages **composable mini-apps** (such as `videos`, `content`, and `analytics` templates) that each maintain their own set of actions and database tables. This modularity isolates heavy workloads—an analytics query running against its own tables does not impact the performance of UI-focused video composition tables.

## Performance Trade-Offs and Considerations

While Agent-Native’s architecture provides significant latency benefits, several trade-offs exist:

- **SQL-only data model**: All state must be expressed in relational tables. Non-relational workloads may require additional mapping layers that could introduce overhead.
- **Index maintenance costs**: Every write to an ownable table updates its composite indexes. While these costs are bounded, write-heavy workloads require monitoring to ensure insert performance remains acceptable.
- **Initial migration overhead**: The first run of migration scripts in [`templates/videos/server/plugins/db.ts`](https://github.com/BuilderIO/agent-native/blob/main/templates/videos/server/plugins/db.ts) creates indexes that may take several seconds on large production tables. This is a one-time cost, but should be planned for during deployment.

## Summary

- **Indexed SQL tables** with composite indexes on `(owner_email, org_id)` and foreign keys ensure O(log n) query performance for scoped reads and permission checks.
- **Unified action API** eliminates redundant network hops by executing database queries server-side and returning complete results to both UI and agent consumers.
- **Real-time sync** through `useDbSync` pushes minimal deltas via lightweight polling, supporting optimistic UI updates without full page reloads.
- **Modular mini-apps** isolate workloads by separating analytics, content, and video tables, preventing resource contention.
- **Write overhead** from index maintenance and the SQL-only constraint require monitoring for high-throughput applications.

## Frequently Asked Questions

### How does Agent-Native handle database indexing for multi-tenant applications?

Agent-Native automatically creates composite indexes on `(owner_email, org_id)` for every ownable table through its migration system in [`templates/videos/server/plugins/db.ts`](https://github.com/BuilderIO/agent-native/blob/main/templates/videos/server/plugins/db.ts). These indexes ensure that tenant-scoped queries filter by ownership in O(log n) time rather than scanning entire tables, while additional indexes on share tables and folder memberships optimize permission checks and join operations.

### What is the network overhead of Agent-Native’s real-time sync mechanism?

The sync mechanism uses lightweight polling against the `application_state` table implemented in [`client/vite-dev-recovery-script.ts`](https://github.com/BuilderIO/agent-native/blob/main/client/vite-dev-recovery-script.ts), transmitting only changed data (deltas) rather than full payloads. This approach minimizes bandwidth compared to traditional REST polling, though it introduces a small constant query load on the database to check for state changes.

### Are there performance differences between SQLite and Postgres in Agent-Native?

The migration scripts use `CREATE INDEX IF NOT EXISTS` syntax that works identically on both SQLite (default for development) and Postgres (production). While the query plans and concurrency handling differ between the two engines, the framework’s index design targets the same access patterns—scoped reads and share table lookups—ensuring consistent O(log n) performance characteristics across both environments.

### How does the action-centric API improve performance compared to traditional REST?

By routing all data access through `defineAction` functions that execute directly on the Nitro server, Agent-Native eliminates the "fetch-then-fetch-again" anti-pattern common in REST APIs. Actions perform multiple database queries server-side and return complete results in a single network round-trip, reducing latency for both UI components and AI agents while ensuring consistent security filtering via `accessFilter`.