How to use Firebase with Spring boot REST Application?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Using Firebase with a Spring Boot REST application usually means one of two things: verifying Firebase Authentication tokens or reading and writing data through the Firebase Admin SDK. The Spring Boot side remains a normal REST API, while Firebase provides external identity, messaging, or database services that your backend can call securely.
Add the Firebase Admin SDK
In a Maven project, start by adding the Firebase Admin dependency.
This SDK is what your Spring Boot application uses to verify tokens and communicate with Firebase services from the server side.
Initialize Firebase Once at Startup
The Admin SDK needs service account credentials and one-time initialization.
In production, the credential file should not be committed to source control. Use a secure deployment mechanism or environment-specific secret management.
Verify Firebase ID Tokens in REST Requests
A common Spring Boot integration is receiving a Firebase ID token from a client and verifying it on the server.
This lets your REST API trust Firebase for authentication while still keeping authorization decisions in your own backend.
Use Firebase Services From Spring Boot
Once initialized, the Admin SDK can also interact with Firebase services such as Firestore or Cloud Messaging.
A simple Firestore example:
This keeps the Spring Boot application as the REST layer while Firebase acts as an external managed backend service.
Keep Authentication and Authorization Separate
Firebase token verification answers "who is this user." Your Spring Boot application still has to answer "what is this user allowed to do."
That means many real systems combine Firebase-authenticated identity with backend-side authorization rules, role checks, or ownership checks in business logic.
If you skip that distinction, you risk treating authentication as if it were the entire security model.
Be Careful With Credentials and Environment Setup
Service account JSON files are sensitive. Do not commit them. Also be explicit about environment setup so local development, CI, and production each load the correct credentials.
A common production pattern is to mount credentials securely or use cloud-native identity instead of keeping static secrets in the container image.
Common Pitfalls
- Treating Firebase Authentication as if it automatically handles all backend authorization.
- Initializing
FirebaseAppmultiple times. - Committing the service account JSON file into source control.
- Verifying the token but never validating application-specific permissions.
- Mixing client-side Firebase SDK expectations with server-side Admin SDK usage.
Summary
- Use the Firebase Admin SDK in Spring Boot for server-side Firebase integration.
- Initialize Firebase once with secure credentials.
- Verify Firebase ID tokens to authenticate REST requests.
- Call Firebase services such as Firestore from ordinary Spring components.
- Keep authentication, authorization, and credential management as separate concerns.
Related reading
- How to use Google API Client Library for JavaScript gapi with async/await?
- How to use host network for docker compose?
- How to use HttpWebRequest .NET asynchronously?
- How to use nginx ingress TCP service on different namespace
- How to use HikariCP in Spring Boot with two datasources in conjunction with Flyway
- How to use Jackson to deserialise an array of objects
- How to use NodePort with kind?
- How to use OpenAPI oneOf property with openapi-generator-maven-plugin when generating Spring code

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.