SucceedHQ Logo SucceedHQ

How to Set Up Firebase Realtime Database for a Nigerian App

By Daniel Lucky · May 27, 2026 · 9 min read

Building an app that works well despite Nigeria’s fluctuating internet connectivity? Firebase Realtime Database offers real‑time sync and offline persistence, making it a strong choice for Nigerian developers. This guide walks you through setting it up from scratch, covering project creation, database configuration, security rules, data operations, and offline handling.

Myth Fact
Firebase is only for big apps. Firebase’s free tier and scalable pricing make it accessible for startups and small projects in Nigeria.
Realtime Database requires constant internet. With offline persistence enabled, the app caches data locally and syncs when the connection returns.
Security rules are too complex. Rules use a simple, JSON‑like language; start with basic locked‑down rules and refine as needed.
Firebase locks you into a single vendor. While Firebase offers integrated services, you can export data and use other tools if needed.
Realtime Database is slow for large datasets. It’s optimized for real‑time sync of small to medium data; for large files, consider Firebase Storage alongside the database.

1. Create a Firebase Project

Go to the Firebase Console (), sign in with your Google account, and click “Add project.” Enter a project name (e.g., “NigerianAppDB”), disable Google Analytics if desired (you can enable it later), and click “Create project.” Wait for Firebase to provision resources.

2. Add Firebase to Your App

Depending on your platform (Android, iOS, web), follow the setup wizard:

3. Initialize the Realtime Database

In the Firebase Console, navigate to “Realtime Database” and click “Create Database.” Choose a location closest to your primary users (e.g., europe-west1 for lower latency to West Africa). Start in “Locked mode” (no read/write access) for security; we’ll adjust rules next.

4. Configure Security Rules

Rules determine who can read or write data. For a basic setup, you might allow authenticated users to read and write their own data:

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

Replace with rules that match your app’s data structure. Always validate data (e.g., ensure a “name” field is a string) to prevent invalid writes.

5. Write Data to the Database

Use the Firebase SDK to write data. Example for web:

import { getDatabase, ref, set } from "firebase/database";

const db = getDatabase();
function writeUserData(userId, name, email) {
  set(ref(db, 'users/' + userId), {
    username: name,
    email: email,
    last_login: Date.now()
  });
}

For Android/iOS, use the respective language‑specific APIs. Always handle potential errors with try/catch or error callbacks.

6. Read Data from the Database

To read data, attach a listener:

import { getDatabase, ref, onValue } from "firebase/database";

const db = getDatabase();
const userRef = ref(db, 'users/' + userId);
onValue(userRef, (snapshot) => {
  const data = snapshot.val();
  // Update UI with data
});

For one‑time reads, use get() instead of onValue(). Remember to detach listeners when appropriate to avoid memory leaks.

7. Enable Offline Persistence

Offline persistence is enabled by default for Firebase Realtime Database on Android and iOS. For web, you need to activate it:

import { getDatabase, enableIndexedDbPersistence } from "firebase/database";

const db = getDatabase();
enableIndexedDbPersistence(db)
  .catch((err) => {
    if (err.code === 'failed-precondition') {
      // Multiple tabs open, persistence can only be enabled in one tab.
    } else if (err.code === 'unimplemented') {
      // The current browser does not support persistence.
    }
  });

Once enabled, the SDK automatically queues writes and syncs when the device regains connectivity.

8. Structure Your Data Efficiently

Realtime Database performs best with flat data structures. Avoid deep nesting; instead, use separate nodes for different entities and link them via keys. Example:

{
  "users": {
    "uid1": { "name": "Ada", "email": "ada@example.com" },
    "uid2": { "name": "Emeka", "email": "emeka@example.com" }
  },
  "posts": {
    "post1": { "author": "uid1", "title": "Hello", "timestamp": 12345 }
  }
}

Denormalize where necessary to reduce the number of listeners and improve read performance.

9. Monitor and Optimize Usage

Use the Firebase Console to monitor database usage (connections, storage, bandwidth). Set up alerts for unusual spikes. Optimize by:

Common Pitfalls and Solutions

Can I use Firebase Realtime Database with React Native?
Yes, Firebase offers official SDKs for React Native via @react-native-firebase/database.
How do I handle data conflicts when multiple users edit offline?
Firebase Realtime Database uses last‑write‑wins for conflicting updates. For more complex conflict resolution, consider using Cloud Functions or custom logic.
Is there a limit to the number of simultaneous connections?
The Spark plan limits to 100 concurrent connections; the Blaze plan scales to 200,000+. Monitor usage in the console.
How do I back up my Firebase Realtime Database?
Firebase offers automated backups (Blaze plan) that export your database to Google Cloud Storage daily. You can also trigger manual exports.
Should I use Realtime Database or Cloud Firestore?
Realtime Database is ideal for real‑time sync and simple hierarchical data. Choose Firestore for more complex queries, automatic scaling, and richer indexing.

Need help setting up Firebase?

Download our Firebase setup checklist for Nigerian developers, including platform‑specific steps and rule templates.

Get the Checklist