Firebase from Google is not just a tool, but an entire ecosystem that radically simplifies the development of mobile applications for Android. If you've ever been faced with the need to create a backend for your application, but were intimidated by the complexity of servers, databases and authentication - Firebase solves 80% of these problems out of the box., allowing you to focus on application logic rather than infrastructure.

Imagine: you need to add registration to your application users, data storage, push notifications and analytics. Without Firebase, you will have to deploy a server, configure a database, write an API, ensure security... The list of tasks grows like a snowball. With Firebase, most of these features are available through a simple SDK and management console - without the need to write server-side code. But how exactly does it work? And why do millions of developers choose this particular tool?

In this article we will look at:

  • ๐Ÿ”ฅ What is Firebase and how does it integrate with Android applications
  • ๐Ÿ“ฆ Key Firebase services that replace the traditional backend
  • ๐Ÿ› ๏ธ Step-by-step connection of Firebase to a project on Android Studio
  • ๐Ÿ’ฐ Tariff plans: when the free plan is no longer enough
  • ๐Ÿš€ Real cases of using Firebase in popular applications
๐Ÿ“Š Have you already tried using Firebase in my projects?
Yes, I actively use it
I tried it, but gave up
I just studied the documentation
Never heard of it

1. Firebase - what is it in simple words?

Firebase is BaaS (Backend-as-a-Service), that is, a cloud platform that provides ready-made solutions for the backend of mobile and web applications. In context Android this means that you can:

  • ๐Ÿ“ฑ Store user data in the cloud without your own server
  • ๐Ÿ” Organize authentication via email, phone or social networks
  • ๐Ÿ“Š Collect usage analytics applications
  • ๐Ÿ”” Send push notifications without complex settings

All these functions are available through Firebase SDK, which connects to your Android project. The main advantage is No need to write server code. For example, to save user data, you don't need to create a REST API or configure a database: just call a method from the SDK, and Firebase will do everything itself.

It is important to understand that Firebase is not just a database. This is a whole set of tools that cover almost all the needs of the mobile backend:

Firebase Service What it replaces Use example
Authentication Own registration/authorization system Login via Google, Facebook or phone number phone
Firestore/Realtime Database Traditional SQL/NoSQL databases Storing user profiles or chat messages
Cloud Messaging (FCM) Server for sending push notifications Alerts about new messages or promotions
Cloud Functions Server logic (microservices) Automatic order processing or report generation
Analytics Analytics systems (for example, Google Analytics) Tracking user activity and events
โš ๏ธ Attention: Firebase is constantly updated. Some features (such as pricing plans or limits) may change. Before using critical services, check the current conditions in official documentation.

2. Why is Firebase better than a traditional backend?

Developers choose Firebase not only because of its simplicity, but also because saving time and resources. Here are the key advantages:

  • โšก Instant deployment: no need to configure the server - just connect the SDK and start using the functions.
  • ๐Ÿ’ฐ Free start: for small projects, the free plan (with restrictions) is enough.
  • ๐Ÿ”„ Real time: Firestore and Realtime Database update data on all devices instantly.
  • ๐Ÿ›ก๏ธ Built-in security: access rules are configured via the console, without writing code.
  • ๐Ÿ“ˆ Scalability: Firebase automatically adjusts to the load - from 10 to 10 million users.

For comparison: if you develop the backend yourself, you will need:

  1. Rent a server (or use a cloud like AWS).
  2. Set up a database (PostgreSQL, MongoDB, etc.).
  3. Implement an API (for example, in Node.js or Python).
  4. Ensure security (authentication, encryption).
  5. Set up monitoring and logging.

With Firebase, all these tasks are solved out of the box. For example, to add authentication via Google, just a few lines of code are enough:

// Example of connecting Google Authentication in Android

FirebaseAuth mAuth = FirebaseAuth.getInstance();

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)

.requestIdToken(getString(R.string.default_web_client_id))

.requestEmail()

.build();

Similar functionality on your own server would require weeks of development.

๐Ÿ’ก

Firebase eliminates the need for 80% of routine configuration tasks backend, allowing you to focus on the unique logic of the application.

3. Key Firebase services for Android developers

Firebase offers more than 20 services, but the following are most in demand for Android applications:

3.1. Firebase Authentication - authentication without headaches

The service allows you to add to the application:

  • ๐Ÿ“ง Registration by email/password
  • ๐Ÿ“ฑ Login via phone number (with SMS code)
  • ๐ŸŒ Authorization via Google, Facebook, Twitter, Apple ID
  • ๐Ÿ”‘ Anonymous login (for testing or guest mode)

Example code for registering a user by email:

mAuth.createUserWithEmailAndPassword(email, password)

.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {

@Override

public void onComplete(@NonNull Task<AuthResult> task) {

if (task.isSuccessful()) {

// User is registered

FirebaseUser user = mAuth.getCurrentUser();

} else {

// Registration error

Toast.makeText(MainActivity.this, "Authentication failed.",

Toast.LENGTH_SHORT).show();

}

}

});

3.2. Cloud Firestore vs Realtime Database - what to choose?

Firebase offers two NoSQL databases:

  • ๐Ÿ”ฅ Realtime Database: data is synchronized in real time, suitable for chats or live updates. Uses a JSON structure.
  • ๐Ÿ“ Cloud Firestore: a more modern database with support for complex queries, transactions and better scalability.

For most new projects it is recommended Firestoreas it:

  • Supports offline mode (data is cached on device).
  • Has a more flexible query system.
  • Scales better with a large number of users.

An example of writing data to Firestore:

// Adding data to the "users" collection

Map<String, Object> user = new HashMap<>();

user.put("name", "Ivan Petrov");

user.put("email", "ivan@example.com");

// Add a document to the collection

db.collection("users")

.add(user)

.addOnSuccessListener(new OnSuccessListener<DocumentReference>() {

@Override

public void onSuccess(DocumentReference documentReference) {

Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId());

}

})

.addOnFailureListener(new OnFailureListener() {

@Override

public void onFailure(@NonNull Exception e) {

Log.w(TAG, "Error adding document", e);

}

});

3.3. Firebase Cloud Messaging (FCM) - push notifications

FCM allows you to send notifications to Android devices (and more). Features:

  • ๐Ÿ”” Support thematic notifications (for example, for all application users).
  • ๐Ÿ“ฑ Personalized messages (based on user data).
  • ๐ŸŒ Works even if the application is closed.

Example of sending a notification via the Firebase console:

  1. Go to Firebase Console โ†’ Cloud Messaging โ†’ New Campaign.
  2. Select the target audience (all users, specific devices or segment).
  3. Write the notification text and click "Review".
  4. Launch the campaign.
How to process a notification in an Android application?

To process notifications, you need to create a service inherited from FirebaseMessagingService, and override the method onMessageReceived. Example:

public class MyFirebaseMessagingService extends FirebaseMessagingService {

@Override

public void onMessageReceived(RemoteMessage remoteMessage) {

// Processing a received message

if (remoteMessage.getNotification() != null) {

String title = remoteMessage.getNotification().getTitle();

String body = remoteMessage.getNotification().getBody();

// Show a notification to the user

}

}

}

Don't forget to add the service to AndroidManifest.xml:

<service

android:name=".MyFirebaseMessagingService"

android:exported="false">

<intent-filter>

<action android:name="com.google.firebase.MESSAGING_EVENT" />

</intent-filter>

</service>

3.4. Firebase Analytics - user data

The service automatically collects information about:

  • ๐Ÿ“ฑ User devices (model, OS, screen resolution).
  • ๐ŸŒ Geographic location.
  • ๐Ÿ•’ Time of use applications.
  • ๐Ÿ”„ Events (for example, button clicks, transitions between screens).

To track custom events (for example, in-app purchases) use:

Bundle params = new Bundle();

params.putString("item_id", "12345");

params.putString("item_name", "Premium subscription");

params.putDouble("price", 9.99);

// Log the purchase event

mFirebaseAnalytics.logEvent("purchase", params);

4. Step-by-step guide: how to connect Firebase to an Android project

Firebase integration takes no more than 10 minutes. Follow the instructions:

Create a project in Firebase Console|Add an application to the project|Download the google-services.json file|Connect Firebase SDK in build.gradle|Synchronize the project in Android Studio-->

Step 1: Create a project in Firebase Console

1. Go to Firebase Console.

2. Click "Add project" and enter a name.

3. Follow the wizard's instructions (you can skip analytics at this stage).

Step 2: Registering an Android application

1. In the project console, click on the Android icon (๐Ÿ“ฑ).

2. Specify package name your application (for example, com.example.myapp).

3. Enter SHA-1 certificate fingerprint (can be obtained through the command:

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

4. Click "Register application".

Step 3: Upload configuration file

1. Download the file google-services.json.

2. Place it in a folder app/ of your Android project.

Step 4: Setting up build.gradle

1. At build.gradle (project level) add:

buildscript {

dependencies {

// Add this line

classpath 'com.google.gms:google-services:4.4.1' // Check the current version!

}

}

2. In build.gradle (module level app) add:

apply plugin: 'com.google.gms.google-services'

dependencies {

// Firebase BoM (Bill of Materials) for version control

implementation platform('com.google.firebase:firebase-bom:32.7.2')

// Add the Firebase libraries you need

implementation 'com.google.firebase:firebase-analytics-ktx'

implementation 'com.google.firebase:firebase-auth-ktx'

}

Step 5: Synchronization and initialization

1. Synchronize the project in Android Studio (click "Sync Now").

2. In the application code (for example, in MainActivity) initialize Firebase:

// Firebase is automatically initialized on the first call

FirebaseApp.initializeApp(this); // Optional in most cases

Done! Now you can use any Firebase services in your application.

โš ๏ธ Attention: If you use ProGuard, add rules for Firebase to the file proguard-rules.pro:
-keepattributes Annotation

-keepclassmembers class * {

@com.google.firebase.* <methods>;

}

Otherwise some functions (for example, authentication) may not work correctly.

5. Firebase tariff plans: how much does it cost?

Firebase offers two main tariffs:

Option Free (Spark) Paid (Blaze, pay-as-you-go)
Authentication Up to 50,000 active users/month $0.01 for each additional user
Cloud Firestore 1 GB of storage, 50,000 reads/day $0.06 for 100,000 reads, $0.18 per GB storage
Realtime Database 1 GB storage, 10 GB download/month $5 per GB storage, $1 per GB download
Cloud Messaging Unlimited number of notifications Free (but there are limits on the frequency of sending)
Hosting 1 GB of storage, 10 GB of traffic/month $0.026 per GB of storage, $0.15 per GB of traffic

For most startups and small projects the free tariff is enough. However, if your app gains popularity, the cost may increase. For example:

  • With 100,000 active users per month for Authentication you will have to pay ~$500.
  • With 1 million readings from Firestore to day - ~$180.

To avoid unexpected bills:

  1. Set up budget alerts in Google Cloud Console.
  2. Use security rules to restrict access to data.
  3. Optimize queries to the database (for example, avoid unnecessary reads).
๐Ÿ’ก

Firebase Console has cost calculator (Project Settings โ†’ Usage and billing โ†’ Pricing calculator), which will help you estimate costs up to scaling.

6. Real cases: where is Firebase used?

Firebase is used in thousands of applications - from startups to large services. Here are some examples:

6.1. Messaging apps

๐Ÿ’ฌ Firebase Realtime Database ideal for chats thanks to:

  • Instant synchronization of messages between devices.
  • Simple data structure (messages are stored as nested objects).
  • Built-in support offline mode.

Example of chat database structure:

{

"chats": {

"chat1": {

"messages": {

"message1": {

"text": "Hello!",

"sender": "user1",

"timestamp": 1634567890

},

"message2": {

"text": "Hello! How are you?",

"sender": "user2",

"timestamp": 1634567895

}

}

}

}

}

6.2. Social networks and applications with user-generated content

๐Ÿ“ธ Services like Instagram or TikTok (in the early stages) could use Firebase for:

  • ๐Ÿ“ฅ Storing posts and media files (via Firebase Storage).
  • ๐Ÿ‘ Likes and comments (Firestore).
  • ๐Ÿ”” Notifications about new activity (FCM).

6.3. Games with online mode

๐ŸŽฎ For mobile games, Firebase provides:

  • ๐Ÿ† Leaderboards (Firestore sorted by points).
  • ๐Ÿ’ฌ Chat between players.
  • ๐Ÿ“Š Analytics of game sessions.

Example code for saving a player's score:

Map<String, Object> scoreData = new HashMap<>();

scoreData.put("userId", "player123");

scoreData.put("score", 1500);

scoreData.put("level", 5);

scoreData.put("timestamp", FieldValue.serverTimestamp());

// Save the result to the "scores" collection

db.collection("scores")

.add(scoreData)

.addOnSuccessListener(...);

6.4. Taxi and delivery services

๐Ÿš– Applications like Uber or Delivery Club could use:

  • ๐Ÿ“ Firestore to track the location of drivers/couriers in real time.
  • ๐Ÿ”” FCM to notify about new orders.
  • ๐Ÿ’ณ Firebase Authentication to register clients and partners.

An example of a data structure for order tracking:

{

"orders": {

"order123": {

"status": "in_progress",

"customerId": "user456",

"driverId": "driver789",

"location": {

"lat": 55.7558,

"lng": 37.6173

},

"timestamp": 1634567890

}

}

}

7. Common mistakes and how to avoid them

Even with Firebase you can encounter problems. Here are the most common mistakes and their solutions:

7.1. Authentication Errors

๐Ÿ” Problem: User cannot login even though the credentials are correct.

Causes and solutions:

  • ๐Ÿ”Œ SHA-1 not added: Make sure the certificate thumbprint is added to the Firebase Console (Project Settings โ†’ General โ†’ Your apps โ†’ SHA certificate fingerprints).
  • ๐Ÿ“ฑ Incorrect package name: Check that the package name in google-services.json matches applicationId in build.gradle.
  • ๐Ÿ”„ Firebase cache: Try clearing the application cache or reinstall it.

7.2. Problems with the database

๐Ÿ—„๏ธ Problem: Data is not saved or read from Firestore/Realtime Database.

What to check:

  • ๐Ÿ”“ Security rules: By default, access to the database is blocked. Configure the rules in Firebase Console โ†’ Database โ†’ Rules. Example for testing:
    rules_version = '2';
    

    service cloud.firestore {

    match /databases/{database}/documents {

    match /{document=**} {

    allow read, write: if request.auth != null;

    }

    }

    }

  • ๐ŸŒ Internet connection: Make sure the device has access to the network.
  • ๐Ÿ”„ Offline mode: Firestore caches data. If you changed the data on the server, but do not see updates, try turning off and turning on the Internet again.

7.3. Push notifications do not arrive

๐Ÿ”” Problem: Notifications are not displayed on the server. device.

Solutions:

  • ๐Ÿ“ฑ Device Token: Make sure you are receiving the FCM token (via FirebaseMessaging.getInstance().getToken()) and sending the notification to the correct token.
  • ๐Ÿ› ๏ธ Service in the manifest: Check that FirebaseMessagingService is declared in AndroidManifest.xml.
  • ๐Ÿ”• Manufacturer restrictions: Some Chinese phones (Xiaomi, Huawei) block notifications. Ask the user to add your application to "autorun".
  • ๐Ÿ“ต Doze Mode: On Android 6+, notifications may not arrive if the application has not been used for a long time. The solution is to use high-priority messages.

7.4. Exceeding the limits of the free plan

๐Ÿ’ฐ Problem: Unexpected bill from Google Cloud.

How to avoid:

  • ๐Ÿ“Š Monitoring usage: Enable alerts about exceeding limits in Google Cloud Console โ†’ Billing โ†’ Budgets & alerts.
  • ๐Ÿ”„ Optimizing queries: Avoid frequently polling the database. For example, instead of a loop with get() use listeners (addSnapshotListener).
  • ๐Ÿ—‘๏ธ Cleaning up old data: Set up automatic removal of outdated records (for example, logs older than 30 days).
โš ๏ธ Attention: If you are testing an application with a large number of records in the database, use Firebase emulators (Firebase Local Emulator Suite). This will avoid real records to the cloud and save money.

8. Firebase Alternatives: When Should You Choose Another Solution?

Firebase is not the only option for the backend. In some cases, it is better to consider alternatives:

Service When to choose Disadvantages compared to Firebase
AWS Amplify Needs tight integration with other AWS services (S3, Lambda) More difficult to set up, more expensive for small projects
Supabase Requires open source code or a PostgreSQL database Fewer ready-made solutions (for example, there is no analogue to FCM)
Parse Server You need to deploy your own backend with open source Requires server administration
Your own backend (Node.js + MongoDB) Unique requirements that Firebase does not cover Long development, high cost of support

When Firebase is not suitable:

  • ๐Ÿ’พ You need a relational database (for example, with JOIN support).
  • ๐Ÿ”ง Full control over the infrastructure is required (for example, for high-load systems).
  • ๐Ÿ’ฐ The project has already grown from a free plan, and Firebase is becoming too expensive.
  • ๐Ÿ”’ Specific security requirements are needed that are not covered by Firebase rules.

However, for 90% of mobile applications (especially at the MVP stage) Firebase remains the optimal choice due to the speed of development and low entry threshold.

๐Ÿ’ก

Firebase is ideal for startups and small teams where it is important to quickly bring a product to market. Large projects with unique requirements may require a combined solution (Firebase + custom backend).

FAQ: Frequently asked questions about Firebase for Android

โ“ Is Firebase free to use?

Yes, Firebase has a free plan Sparkthat covers basic needs small projects:

  • Up to 50,000 active users per month for Authentication.
  • 1 GB of storage in Firestore i