Firebase Realtime Database is Google's cloud-hosted NoSQL database that stores data as JSON and synchronizes it in real-time across all connected clients—typically within milliseconds. Unlike traditional databases requiring HTTP polling, it uses WebSocket-based data synchronization where every write instantly pushes updates to all listening devices, making it ideal for collaborative apps, chat systems, and live dashboards. Data persists locally during offline periods and automatically syncs when connectivity returns, merging conflicts server-side. A key design principle: flatten your data structure aggressively—because fetching a node retrieves all child data, deeply nested trees force massive downloads and break granular security rules, so denormalization (duplicating data across paths) is the norm, not the exception.
What This Cheat Sheet Covers
This topic spans 19 focused tables and 142 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: SDK Initialization & Setup
Every Firebase app starts here—wiring up the SDK, pointing it at your database, and grabbing references to the JSON paths you'll read and write. The databaseURL format varies by region, and connecting to the local emulator is a one-liner you slot in right after getDatabase().
| Method | Example | Description |
|---|---|---|
import { initializeApp } from "firebase/app"const app = initializeApp({ databaseURL: "https://NAME.firebaseio.com" }) | • Initializes the Firebase app with your project config • databaseURL is required for RTDB. | |
import { getDatabase } from "firebase/database"const db = getDatabase(app) | • Returns the database service instance • pass app explicitly when using multiple Firebase apps. | |
import { ref } from "firebase/database"const usersRef = ref(db, 'users/123') | • Creates a database reference to a specific path • root reference: ref(db) with no path. |