How to fix database/unavailable in Firebase

FirebaseINTERMEDIATEHIGHUpdated Dec 22, 2025· 159 views

The Firebase database/unavailable error occurs when your application cannot connect to the Firebase Realtime Database or Firestore service. This is often a transient network issue that can be resolved with proper retry logic and connection verification.

Quick fix

Fixes database/unavailable

navigator.onLine ? console.log("Online") : console.log("Offline");
  1. Check Firebase Service Status
  2. Verify Your Network Connection
  3. Re-initialize Firebase and Check Configuration
  4. Implement Exponential Backoff Retry Logic
firebase — error
navigator.onLine ? console.log("Online") : console.log("Offline");
database/unavailable

What this error means

This error indicates that your Firebase application lost connectivity to the backend database service. The Firebase SDK cannot establish or maintain a connection to either the Realtime Database or Firestore, preventing read and write operations from completing. This can happen due to temporary network issues, service interruptions, authentication problems, or configuration errors. When this error occurs, your app typically enters offline mode or fails to execute database queries. The error usually includes a message like "The service is currently unavailable" or "Could not reach [Firestore/Realtime Database] backend." Unlike permission errors or missing data errors, an unavailable database indicates a connectivity problem between your client and Firebase infrastructure.

Typical symptoms

  • Database queries fail to execute or timeout after 10+ seconds
  • Read operations return no data or errors without logs explaining why
  • Write operations hang or fail silently in production
  • Firebase console works but your app cannot connect
  • Error messages mention "could not reach backend" or "service unavailable"
  • The app works on some networks but fails on others (WiFi vs cellular)

Common causes

  1. Temporary Firebase service outage or degraded performance affecting your region
  2. Poor network connectivity on client device preventing backend communication
  3. Firewall or VPN blocking Firebase connection endpoints
  4. Incorrect Firebase configuration or missing initialization parameters
  5. Authentication token expired or invalid, causing failed authentication
  6. Regional database selection causing network latency or unavailability in your area
  7. Security rules configured to deny all access, causing the database to become inaccessible
  8. SDK version incompatibility or outdated Firebase client library

How to fix "database/unavailable"

1Check Firebase Service Status

Before assuming the error is client-side, verify Firebase services are operational.

Visit the Firebase Status Dashboard at https://status.firebase.google.com/ to check if there are any ongoing incidents affecting Realtime Database or Firestore in your region. If there is a service outage, wait for Firebase to restore service—there is nothing you can do on your client until the backend is available.

2Verify Your Network Connection

Ensure your device has a healthy internet connection.

Run a simple test:

javascript
navigator.onLine ? console.log("Online") : console.log("Offline");

If offline, connect to a working network. If still failing after connecting, try:
- Switching from WiFi to cellular or vice versa
- Using a different network entirely
- Checking if a VPN or firewall is blocking Firebase endpoints (*.firebase.io)

3Re-initialize Firebase and Check Configuration

Verify your Firebase config is correct and properly initialized.

javascript
import { initializeApp } from "firebase/app";
import { getDatabase } from "firebase/database"; // or getFirestore() for Firestore

const firebaseConfig = {
  apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
  authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
  databaseURL: process.env.REACT_APP_FIREBASE_DATABASE_URL, // Required for Realtime DB
  projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
  storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
  messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
  appId: process.env.REACT_APP_FIREBASE_APP_ID,
};

const app = initializeApp(firebaseConfig);
const database = getDatabase(app); // Verify this succeeds

Missing or invalid databaseURL is a common cause, especially for Realtime Database in non-US regions.

4Implement Exponential Backoff Retry Logic

Firebase recommends handling transient unavailability with retry logic.

javascript
async function queryWithRetry(dbRef, maxRetries = 3) {
  for (let attempt = 1; attempt <= maxRetries; attempt++) {
    try {
      const snapshot = await get(dbRef);
      return snapshot.val();
    } catch (error) {
      if (error.code === "UNAVAILABLE" && attempt < maxRetries) {
        const delayMs = Math.min(1000 * Math.pow(2, attempt - 1), 10000);
        console.log(`Retry attempt ${attempt} after ${delayMs}ms...`);
        await new Promise(r => setTimeout(r, delayMs));
      } else {
        throw error;
      }
    }
  }
}

This exponential backoff approach (1s, 2s, 4s...) gives transient issues time to resolve without overwhelming the backend.

5Enable Network if Offline

For Firestore, explicitly enable network if the SDK is in offline mode.

javascript
import { enableNetwork } from "firebase/firestore";

const db = getFirestore(app);
await enableNetwork(db); // Force reconnection

For Realtime Database, reconnection typically happens automatically, but you can trigger it by disabling and re-enabling listeners.

6Check and Fix Security Rules

If your database rules deny all access, Firebase disables the database. Verify your security rules in the Firebase Console under Database > Rules.

For development/testing, temporarily use permissive rules:

json
{
  "rules": {
    ".read": true,
    ".write": true
  }
}

For production, implement proper authentication-based rules:

json
{
  "rules": {
    "users": {
      "$uid": {
        ".read": "$uid === auth.uid",
        ".write": "$uid === auth.uid"
      }
    }
  }
}

After updating rules, wait 2-3 minutes for changes to propagate.

7Upgrade Firebase SDK to Latest Version

Outdated SDK versions may have connectivity bugs or incompatibilities.

For npm/Node.js projects:

bash
npm install firebase@latest

For React Native:

bash
npm install @react-native-firebase/database@latest

For Flutter:

bash
flutter pub upgrade cloud_firestore

After upgrading, clear your cache and rebuild/restart your app.

8Monitor Network and Implement Offline Support

Add offline mode support to gracefully handle unavailability.

javascript
import { onDisconnect } from "firebase/database";

const connectedRef = ref(db, ".info/connected");
const userStatusDatabaseRef = ref(db, "status/" + uid);

onValue(connectedRef, (snapshot) => {
  if (snapshot.val() === true) {
    console.log("Connected");
    set(userStatusDatabaseRef, true);
    onDisconnect(userStatusDatabaseRef).set(false);
  } else {
    console.log("Disconnected - operating in offline mode");
  }
});

This allows your app to detect when Firebase is unavailable and adapt behavior accordingly.

Advanced notes

Regional Deployment Considerations: Users in some regions (particularly Europe and Asia) have reported better success by explicitly selecting US-central1 as their database region, as some regional deployments may experience higher latency or availability issues. Check your Firebase Console project settings.

Android-Specific Issues: On Android, the unavailable error is more frequent and sporadic than on web or iOS. Ensure you have adequate memory available and consider reducing the amount of data you sync to the client using queries.

Browser Compatibility: Older versions of Edge and Safari have had issues reaching Firebase backends. Test on Chrome or Firefox if you suspect browser-specific problems.

Rate Limiting and Quota: If you receive unavailable errors during periods of high traffic, you may be hitting Firebase quota limits. Check your Firebase Console for any quota warnings and consider upgrading your billing plan.

Frequently asked questions

What does "database/unavailable" mean?
This error indicates that your Firebase application lost connectivity to the backend database service. The Firebase SDK cannot establish or maintain a connection to either the Realtime Database or Firestore, preventing read and write operations from completing. This can happen due to temporary network issues, service interruptions, authentication problems, or configuration errors.
How do I fix "database/unavailable"?
The Firebase database/unavailable error occurs when your application cannot connect to the Firebase Realtime Database or Firestore service. This is often a transient network issue that can be resolved with proper retry logic and connection verification.
What causes "database/unavailable"?
Temporary Firebase service outage or degraded performance affecting your region Poor network connectivity on client device preventing backend communication Firewall or VPN blocking Firebase connection endpoints
Is the "database/unavailable" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading