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.
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.
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.
Ensure your device has a healthy internet connection.
Run a simple test:
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)
Verify your Firebase config is correct and properly initialized.
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 succeedsMissing or invalid databaseURL is a common cause, especially for Realtime Database in non-US regions.
Firebase recommends handling transient unavailability with retry logic.
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.
For Firestore, explicitly enable network if the SDK is in offline mode.
import { enableNetwork } from "firebase/firestore";
const db = getFirestore(app);
await enableNetwork(db); // Force reconnectionFor Realtime Database, reconnection typically happens automatically, but you can trigger it by disabling and re-enabling listeners.
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:
{
"rules": {
".read": true,
".write": true
}
}For production, implement proper authentication-based rules:
{
"rules": {
"users": {
"$uid": {
".read": "$uid === auth.uid",
".write": "$uid === auth.uid"
}
}
}
}After updating rules, wait 2-3 minutes for changes to propagate.
Outdated SDK versions may have connectivity bugs or incompatibilities.
For npm/Node.js projects:
npm install firebase@latestFor React Native:
npm install @react-native-firebase/database@latestFor Flutter:
flutter pub upgrade cloud_firestoreAfter upgrading, clear your cache and rebuild/restart your app.
Add offline mode support to gracefully handle unavailability.
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.
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.
Callable Functions: INTERNAL - Unhandled exception
How to fix "Callable Functions: INTERNAL - Unhandled exception" in Firebase
auth/invalid-hash-algorithm: Hash algorithm doesn't match supported options
How to fix "auth/invalid-hash-algorithm: Hash algorithm doesn't match supported options" in Firebase
Hosting: CORS configuration not set up properly
How to fix CORS configuration in Firebase Hosting
auth/reserved-claims: Custom claims use reserved OIDC claim names
How to fix "reserved claims" error when setting custom claims in Firebase
Callable Functions: UNAUTHENTICATED - Invalid credentials
How to fix "UNAUTHENTICATED - Invalid credentials" in Firebase Callable Functions