How to Embed a Neon Dashboard in Your App
Embed a Neon dashboard in your app. Connect a read-only role to a read replica, scope each customer with RLS and request embed URLs from a Next.js route.

Your customer success lead posts in the product channel on Monday morning.
Customer success lead: Our biggest account wants bookings by location again. That's four Mondays in a row I've emailed them a CSV.
Engineer: It's all in Neon. Bookings, locations, cancellations.
Customer success lead: Could it live in the app instead of my outbox?
Engineer: A dashboard for every customer. Neon scales to zero when it's idle. I was hoping to do the same this week.
You don't have to build that dashboard from scratch. Below, you'll embed a Neon dashboard in your app with Draxlr. Its row-level security scopes each customer to their own bookings, and the dashboard's queries stay off the compute your app writes to.
Three Neon details shape the setup: the dashboard's login is created in SQL, Neon suggests a separate compute for BI tools, and a sleeping compute adds a short wait. We tested all three on a throwaway Neon project. Already connected Neon to Draxlr with the string from our guide to building dashboards from a Neon database? Steps 2 and 3 replace that login.
Key takeaways
- A role created with SQL reads only the tables you grant it. In our test it couldn't write, create roles or read a table added later, and its timeout cancelled a long query at 15 seconds.
- Neon recommends a read replica for BI tools. Ours refused writes, even from
neondb_owner, and showed a new row on its very next read.- After Neon suspended the replica, opening a connection and running one dashboard query took 1.5 seconds, against 0.6 seconds warm.
What you need before you start
- A Neon project where every customer-owned table carries a tenant column. This guide calls it
org_id. - A membership table, such as
org_members, so your backend can confirm which orgs a user belongs to. - Draxlr on Power or above. Embedding comes with every plan, from Premium at $75 a month. Row-level security, which this guide relies on, starts with Power at $250 a month.
- A backend route that requests embed URLs. The example uses a Next.js route handler, but any server works.
This guide assumes customers share tables and a column like org_id tells their rows apart. Some teams give each customer their own Neon project instead, which makes each project a separate connection. Our comparison of multi-tenant isolation models covers that trade-off.
Neon joined Databricks in 2025, and Neon's Neon and Lakebase page now calls the database itself Lakebase Postgres. The steps below are the same.
How does an embedded Neon dashboard work?
Two Neon computes do different jobs here. Your primary answers the membership check, and a read replica answers every dashboard query. The browser asks only your route for the embed URL, so it never holds a Draxlr secret, and Draxlr only receives an org ID the route has confirmed.
Step 1: Add a read replica for the dashboard
For BI tools like Draxlr, Neon's guide to connecting GUI applications recommends "using a read replica instead of your main database compute". An embedded dashboard is a BI workload that your customers trigger.
Neon's read replicas "do not replicate or duplicate data". They're separate computes that read the same storage as your primary. So you don't pay for a second copy of the data, and the replica has its own size and autoscaling settings.
To add one, open Branches in the Neon Console, select your production branch and click Add Read Replica. With the CLI, run neon branches add-compute <branch> --type read_only, using your branch name (main in our new test project). Any plan can add one. The Free plan allows 3 per project, and each replica is billed as compute.
We tested on a new Neon project running Postgres 18.7, with 600,000 bookings split across 30 orgs. On the replica, even a write as the project's owner role, neondb_owner, failed with "ERROR 25006: cannot execute INSERT in a read-only transaction". We then inserted a row on the primary and queried the replica straight after, over a fresh connection. The new row was already there.
Small app with light dashboards? You can skip the replica and point Draxlr at your primary compute. Keep the timeout from Step 2 either way.
Step 2: Create a read-only role with SQL
Neon's roles guide says roles created with SQL "are not granted membership in the neon_superuser role". Roles created in the Console or API are admins. That makes SQL the right tool for a dashboard login.
Run this in the Neon SQL Editor, on the primary compute of your production branch:
create role analytics_ro with login password 'paste-a-generated-password';
grant usage on schema public to analytics_ro;
grant select on public.bookings, public.locations, public.booking_statuses to analytics_ro;
-- Only for tables with RLS: let this role read rows,
-- and Draxlr narrows them per customer in Step 5
create policy analytics_ro_reads on public.bookings
for select to analytics_ro using (true);
-- Cancel runaway dashboard queries
alter role analytics_ro set statement_timeout = '15s';
The create policy line is only for tables that already use Postgres row-level security. Those policies match rows to an org value your app sets on each request, and Draxlr's connection doesn't set one, so analytics_ro would otherwise see 0 rows. Your app's own policies stay exactly as they are.
Neon requires a password with at least 60 bits of entropy. A generated string of 24 or more mixed characters clears that easily. When the dashboard grows, grant the new table too, plus a policy if it uses RLS. Keep anything that holds tokens or secrets off the list.
Roles in Neon belong to a branch. Create this one on the branch the dashboard reads, usually production. Branches you create afterwards get a copy, and the read replica uses it right away, because it reads the same branch.
In our test, a 20-second query as analytics_ro was cancelled at 15.2 seconds. Inserts, deletes, create table and create role all failed. We then added an api_tokens table, and analytics_ro got "permission denied for table api_tokens". The role also worked on the replica, with the same timeout.
Step 3: Connect Neon to Draxlr
Neon offers two connection strings. The pooled one, with -pooler in the hostname, runs PgBouncer in transaction mode. Neon's connection pooling guide lists "long-running analytics queries" and session settings among the cases for a direct connection. Draxlr keeps its own small connection pool, so use the direct string.
- In Neon, click Connect. Pick your production branch, your database and the
analytics_rorole. - Choose the Replica compute and switch Connection pooling off. The hostname shouldn't contain
-pooler. - In Draxlr, add a database and choose Neon.
- Enter the host, port 5432 and database name from that string, the user
analytics_ro, and the password you generated in Step 2. - Select the
publicschema, or whichever schemas hold your tables.
Already connected Neon to Draxlr with another login? Edit that connection in Draxlr instead of adding a new one. Swap in the replica host, analytics_ro and its password. Dashboards that use only the granted tables keep working, so keep internal dashboards that need other tables on a separate connection.
Neon rejects unencrypted connections, according to its security guide, and Draxlr connects over SSL, so there's nothing extra to set.
On the Scale plan you can turn on IP Allow. Draxlr's connection form shows the IP address to put on that list.
Step 4: Build the dashboard
For a bookings product, start with four to six items:
- Bookings this month as a single number
- Confirmed bookings by week, a line chart customers can drill into
- Upcoming bookings, a table with date, location and status
- Cancellations by location, a pivot with a column per month
Build each one with the query builder, by asking the AI in plain English, or in the SQL editor when you need joins or Postgres date functions. Every item runs its own live query when a customer opens the dashboard, so each extra item adds a query to every view.
Plan for Step 5 while you build. The row rule is set per table, so every customer table on the dashboard needs its own org_id. In SQL items, put a tenant table such as bookings after FROM and bring in the rest with INNER or LEFT joins. That way the row rule filters the rows the query starts from.
Step 5: Scope each customer with Draxlr row-level security
Draxlr's row-level security for embeds comes with Power and higher plans. You set it up once, in three pieces:
- Permission. Choose the tables the embed may query and give each one a row rule. Here,
bookings.org_idandlocations.org_idmust match anorgIdattribute. A shared lookup table likebooking_statusescan go in without a rule. - RLS group. Name it
Customersand attach the permission. - Token values. Your route sends the group name and the customer's
orgIdwhen it asks for an embed URL.
Draxlr signs both values into the embed token. Every query behind the embed then gets the row rule, whether a filter, a drill-down or an export triggered it. Tables left out of the permission can't be queried at all. Our guide to Postgres row-level security for multi-tenant analytics compares this with database policies.
To check the setup, type a real org ID into the Row-level security panel of Draxlr's embed builder. The preview shows that customer's version of the dashboard.
Step 6: Request the embed URL from a Next.js route
The example is a Next.js route handler, and the same logic works in any backend. Store DRAXLR_API_KEY, DRAXLR_API_SECRET and DRAXLR_DASHBOARD_ID as server environment variables. Never give the secret a NEXT_PUBLIC_ prefix, because Next.js ships those values to the browser.
The membership check uses Neon's serverless driver over HTTP and your app's usual DATABASE_URL. The Draxlr call follows the Generate Embed URL API reference:
// app/api/analytics-embed/route.ts
import { neon } from '@neondatabase/serverless'
import { getUserId } from '@/lib/auth' // your auth: Neon Auth, Clerk, Auth.js...
const sql = neon(process.env.DATABASE_URL!)
const DRAXLR_API = 'https://api.draxlr.com/api/dashboardGroup/generate-embed-url/'
export async function POST(req: Request) {
const userId = await getUserId(req)
if (!userId) return new Response('Sign in first', { status: 401 })
const { orgId } = await req.json().catch(() => ({}))
if (!orgId) return new Response('orgId required', { status: 400 })
// Runs on your primary, as your app's own role
const [member] = await sql`
select org_id from org_members
where user_id = ${userId} and org_id = ${orgId}`
if (!member) return new Response('Not a member of this org', { status: 403 })
const res = await fetch(DRAXLR_API + process.env.DRAXLR_DASHBOARD_ID, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
apiKey: process.env.DRAXLR_API_KEY,
apiSecret: process.env.DRAXLR_API_SECRET,
embedOptions: {
rlsGroup: 'Customers',
attributes: { orgId: member.org_id },
},
}),
cache: 'no-store',
})
const data = await res.json().catch(() => ({}))
if (!data.success) return new Response(data.error ?? 'Embed failed', { status: 502 })
return Response.json({ embedUrl: data.embedUrl })
}
Notice the split. The membership lookup runs on your primary, next to the rest of your app's traffic, and nothing reaches the replica until Draxlr runs the dashboard. An orgId edited in the browser fails that lookup and gets a 403, before any bookings are queried.
Header, export and theme settings go in a configuration object inside embedOptions. Draxlr's embed builder generates it for you.
Step 7: Render the dashboard in your app
Draxlr's embed code comes in HTML, React and Vue versions. For a Next.js app, the React component from react-draxlr-embed is the natural fit. When the user switches orgs, the effect below fetches a new URL, and the component loads that org's dashboard:
'use client'
import { useEffect, useState } from 'react'
import DraxlrEmbed from 'react-draxlr-embed'
export function BookingsAnalytics({ orgId }: { orgId: number }) {
const [embedUrl, setEmbedUrl] = useState<string>()
const [failed, setFailed] = useState(false)
useEffect(() => {
let cancelled = false // ignore a slow reply for an org the user has left
setEmbedUrl(undefined)
setFailed(false)
fetch('/api/analytics-embed', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ orgId }),
})
.then((res) => (res.ok ? res.json() : Promise.reject(res.status)))
.then((data) => !cancelled && setEmbedUrl(data.embedUrl))
.catch(() => !cancelled && setFailed(true))
return () => {
cancelled = true
}
}, [orgId])
if (failed) return <p>Analytics didn't load. Please try again.</p>
if (!embedUrl) return <p>Loading analytics...</p>
return (
<DraxlrEmbed
id="YOUR_DASHBOARD_ID"
type="dashboardGroup"
embedUrl={embedUrl}
apiKey="" // unused with embedUrl, but the package's types require it
options={{}}
iframeStyle={{ width: '100%', minHeight: '600px', maxHeight: '2000px' }}
/>
)
}
The id must match DRAXLR_DASHBOARD_ID, because the component uses it to pick up the dashboard's height updates. Pass the empty options object as well. The package adds it to the embed URL, and without it the URL ends in embedOptions=undefined. Errors are handled in the fetch, because the component's onError only covers its own API calls.
Draxlr chooses the light or dark theme from the background color in your embed settings. Give it a full six-digit hex code, like #0f172a for a dark app. Apps with a theme toggle need one embed URL per theme, as our dark and light mode embedding guide explains.
What does scale to zero mean for an embedded dashboard?
By default, Neon suspends a compute after 5 minutes without queries. Its compute lifecycle docs say waking it "generally takes a few hundred milliseconds", and that memory buffers start cold, so the first queries run slower. For an embedded dashboard, the first customer after a quiet spell waits a little longer.
We measured it on our 0.25 CU replica. We suspended it five times through Neon's API, as scale to zero would, and timed the next request. Each request opened a connection and ran one dashboard item's query: confirmed bookings by week for one org. Ten warm requests gave the baseline.
| Step (median) | Warm compute | Right after a suspend |
|---|---|---|
| Open a connection | 465 ms | 992 ms |
| Run the bookings-by-week query | 74 ms | 464 ms |
| Total | 598 ms | 1,511 ms |
Each figure is a median, and the totals include a quick select 1, so the rows don't add up exactly. Our client sat in India and the replica in Singapore, so network distance inflates both columns. A real Draxlr dashboard runs several queries from Draxlr's servers, so its numbers will differ. The gap is the part to plan for: about half a second to wake the compute, and slower first queries while memory warms up.
Is that worth fixing? Not for a dashboard customers open once a week, but a dashboard on your app's home screen should stay awake. Neon's plans page sets out the options:
| Neon plan | Scale to zero | Compute price |
|---|---|---|
| Free | After 5 minutes, can't be turned off | 100 CU-hours per project included |
| Launch | After 5 minutes, can be turned off | $0.106 per CU-hour |
| Scale | From 1 minute to always on | $0.222 per CU-hour |
At those rates, an always-on 0.25 CU replica uses about 183 CU-hours a month, roughly $19 on Launch or $41 on Scale. The setting is per compute, so your primary keeps its own. On Free, every compute in the project draws from the same 100 CU-hours, which means a busy replica eats into your primary's budget.
Before you launch
- Replica, not primary. Run
select current_user, pg_is_in_recovery()in Draxlr's SQL editor. You wantanalytics_roandtrue. Afalsemeans Draxlr is still on your primary compute. - No
-poolerhost. The connection's hostname should be the replica's direct endpoint. - Two orgs side by side. Generate a URL for each org and compare every item, then repeat with filters and drill-downs applied.
- Grants and permission match. The role's grants and the Draxlr permission list the same few tables.
- Secret stays server-side. Search your built JavaScript for the API secret, and make sure no
NEXT_PUBLIC_variable holds it. - A cold open. Leave the dashboard alone for 10 minutes, then open it and judge the wait yourself.
- Allowed domains. The embed settings name only the domains your app runs on.
When customers want to build their own reports
Sooner or later, a customer asks for a cut of their bookings that your dashboard doesn't have. That's the moment to look at full app embedding, which also comes with Power. Each customer gets an analytics workspace inside your product: the dashboards you share, dashboards and saved queries of their own, and an AI assistant, query builder and SQL editor.
On the Neon side, the same role and replica serve it. Keep the permission's table list short, because customers now write their own queries. Your route calls the full app embed API instead and adds a user identifier next to the RLS group and orgId. In the frontend, Draxlr's HTML snippet replaces the React component. Our single dashboard vs full app embedding comparison helps you choose.
Conclusion
Embedding a Neon dashboard is mostly about giving the dashboard its own lane:
- A read replica, so customer queries don't compete with your app's writes
- A role created in SQL, with explicit grants and a statement timeout
- Draxlr row-level security on
org_id, with the org checked by your route - A conscious choice about scale to zero for the replica
Running Postgres somewhere other than Neon? Our guide to embedding a PostgreSQL dashboard covers the general setup. For plans and features, see Draxlr for Neon and the embedded analytics tool page.
Connect your Neon databaseFAQs
1. Can I embed a Neon dashboard in my app?
Yes. Point an embedded analytics tool at a Neon read replica, build the dashboard and render it with the tool's embed code. Draxlr provides HTML, React and Vue code plus a backend API, so your server requests a fresh signed URL each time a customer opens the page.
2. Should a BI tool use Neon's pooled or direct connection?
Use the direct connection, without -pooler in the hostname. Neon's pooler runs PgBouncer in transaction mode, and Neon's docs list long-running analytics queries and session settings among the cases for a direct connection. Point it at a read replica, as Neon recommends for BI tools.
3. Which Postgres role should an embedded dashboard use on Neon?
A dedicated role created with SQL, which Neon doesn't add to neon_superuser, its admin role. Grant SELECT on just the tables the dashboard uses, add a select policy on tables that already use Postgres RLS, and set a statement timeout so long queries get cancelled.
4. Will scale to zero slow down an embedded dashboard?
A little, for the first viewer after 5 idle minutes. In our test, the first connection and query after a suspend took about 1.5 seconds, against 0.6 seconds warm. On Neon's Launch and Scale plans, you can keep the dashboard's read replica always on.
5. How do I limit each customer to their own rows?
Apply row-level security in the analytics tool, keyed on your tenant column. In Draxlr, a permission adds a row rule like org_id equals orgId to each table, and an RLS group uses that permission. Your backend confirms the user's org before passing both values with the embed URL request.
About the author

Vivek is a coder and the founder of Draxlr who cares deeply about building good products. He works at the intersection of AI, SQL, dashboards, and embedded analytics, with a strong focus on making complex data workflows feel simple, useful, and fast for real teams.
If you have questions about anything in this guide, or want to compare options for your specific stack, you can email Vivek at vivek@draxlr.com, try Draxlr free, or reach out directly through the Draxlr team.

