dentvega/firebase-agent-skills/firebase-realtime-database
Claude Code and agent skill by dentvega/firebase-agent-skills
- community
Checking that the SKILL.md file is still in the repository.
Sets up and uses Firebase Realtime Database (RTDB) — provisioning, security rules in the JSON expression format, presence detection with onDisconnect, low-latency chat patterns, and shallow vs. deep queries. Use when the user needs presence (online/offline), real-time chat with minimal latency, collaborative cursor state, or any data that's tree-shaped and changes by the millisecond. For document-oriented or large-scale data, prefer Firestore.
Install
npx vskill@latest install dentvega/firebase-agent-skills/firebase-realtime-databaseSKILL.md
The same SKILL.md was published earlier as dentvega/firebase-agent-skills/firebase-realtime-database.
Firebase Realtime Database
Minimum viable example
RTDB vs. Firestore — pick one
| Use RTDB | Use Firestore | |
|---|---|---|
| Presence (online users) | Almost everything else | |
| Sub-100ms collaborative cursors | Document-oriented data | |
| Append-only logs at high frequency | Complex queries with where + orderBy | |
| Simple tree shapes | Cross-collection joins | |
| Sub-1ms read latency required | Strong schema validation |
RTDB charges by bytes downloaded and concurrent connections. Firestore charges by operations. For chat with 100k messages, RTDB tends to be cheaper; for a CRUD app with mostly cold data, Firestore wins.
In a single app, use both: Firestore for the main data model, RTDB for presence and ephemeral live state.
1. Initialize
Generates database.rules.json. Pick a location at creation; cannot be changed.
Default-deny. Open up paths explicitly.
2. Security rules — different from Firestore
Rules are a JSON tree mirroring your data tree, with .read, .write, .validate expressions at each node:
Key differences from Firestore:
- No `request.auth.uid` — it's
auth.uid - `data` is existing,
newDatais the proposed value - `.read` / `.write` cascade down — granting at a parent path grants for everything under it (in Firestore, rules don't cascade)
- `.indexOn` required to use
orderByChildon that key, similar to Firestore composite indexes but per-path
Deploy:
3. Presence detection (the killer feature)
RTDB's onDisconnect runs server-side when the client connection drops — even on crash or network failure. Firestore has no equivalent.
The .info/connected node tracks the actual connection state. The onDisconnect().remove() is registered server-side and fires when the connection drops. Result: /presence/{uid} reliably reflects who's online without polling.
For "last seen" in addition to online state:
4. Querying
RTDB queries are limited compared to Firestore — you can sort by one field and filter by one range. No compound queries.
For complex filtering, fan-out write to denormalized indexes:
Atomic multi-path update — both or neither.
5. Cost — minimize bytes downloaded
RTDB downloads the entire subtree you reference. ref('/messages').on('value', ...) downloads every message in every room — terrible. Always scope to the smallest path:
- ✅
ref('/messages/room-123').limitToLast(50) - ❌
ref('/').on('value', ...)
Use .indexOn so range queries don't scan client-side.
For data that should only fetch once, use .once('value') instead of .on('value') to avoid the persistent connection cost.
6. Client SDK setup
Web
Expo / React Native
7. Emulator
Connect:
8. Common mistakes
- Listening at the root.
.on('value')on/downloads the entire database. Always scope to the smallest path. - No `.indexOn` for `orderByChild`. Works locally because the emulator does in-memory sort; in production, rules reject the query.
- Forgetting to call `.off()` on unmount. Listeners leak; bandwidth + connection bills grow.
- Trying to do compound queries. RTDB can sort by one field, filter by one range. Use denormalized fan-out indexes for everything else.
- Storing growing arrays. RTDB has no array type — what looks like an array is
{0: x, 1: y, ...}. Usepush()for auto-IDs instead of array indexes. - Forgetting `onDisconnect` doesn't fire on the client. It's registered server-side and runs after the connection drops. Test it by killing the device's network, not by closing the app gracefully.
- Mixing RTDB and Firestore listeners on the same data. Pick one source of truth per piece of state.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/firebase-realtime-database/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/dentvega/firebase-agent-skills/firebase-realtime-database)