Posted in

Top 30 Firebase Interview Questions and Answers for All Levels

Prepare for your Firebase developer interview with these 30 carefully curated questions and answers. Covering basic concepts to advanced scenarios, this guide helps freshers, candidates with 1-3 years experience, and 3-6 years professionals master Firebase fundamentals and best practices.

Basic Firebase Interview Questions (1-10)

1. What is Firebase and what are its main services?

Firebase is Google’s mobile and web application development platform that provides backend services. Main services include Realtime Database, Cloud Firestore, Authentication, Cloud Functions, Hosting, Storage, and Analytics.[1][5]

2. What is the difference between Firebase Realtime Database and Cloud Firestore?

Realtime Database uses a single JSON tree with real-time synchronization, while Cloud Firestore offers document-collection data model, better querying, offline support, and superior scalability for new projects.[1][5]

3. How do you initialize Firebase in a web application?

Initialize Firebase using the configuration object and Firebase app instance:

const firebaseConfig = {
  apiKey: "your-api-key",
  authDomain: "your-project.firebaseapp.com",
  projectId: "your-project-id",
  storageBucket: "your-project.appspot.com",
  messagingSenderId: "123456789",
  appId: "your-app-id"
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
const auth = getAuth(app);

[5]

4. What are Firebase Security Rules?

Firebase Security Rules are server-side rules that control read/write access to Firebase services like Firestore and Storage based on authentication and data validation.[5]

5. How do you write basic Firestore security rules?

Example of Firestore security rules allowing users to access only their own documents:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId} {
      allow read, write: if request.auth != null && request.auth.uid == userId;
    }
  }
}

[5]

6. What is Firebase Authentication?

Firebase Authentication provides backend services for user sign-in using email/password, phone, social providers (Google, Facebook), and anonymous login with secure token management.[1][2]

7. How do you read data from Firestore?

Get a single document from Firestore:

const docRef = doc(db, 'users', 'docId');
const docSnap = await getDoc(docRef);
if (docSnap.exists()) {
  console.log('Document data:', docSnap.data());
} else {
  console.log('No such document!');
}

[5]

8. What is Firebase Hosting?

Firebase Hosting provides fast, secure hosting for web apps with global CDN, SSL certificates, and custom domain support with automatic deployment capabilities.[1]

9. How does real-time data synchronization work in Firebase?

Firebase uses WebSocket connections to push data changes instantly to connected clients. Clients listen to specific database paths and receive updates automatically.[1][4]

10. What are Firebase Cloud Functions?

Cloud Functions are serverless functions that run in response to events like database changes, HTTP requests, or authentication triggers without managing servers.[1][5]

Intermediate Firebase Interview Questions (11-20)

11. How do you handle errors in Firebase operations?

Use try-catch blocks for async operations, check error.code for specific error types, and implement user-friendly error messages using Firebase error codes for authentication and network issues.[1]

12. What are Firebase custom claims and their use case?

Custom claims are key-value pairs set on user accounts via Admin SDK for role-based access control (RBAC). Example: {"role": "admin"} accessible in security rules.[2]

13. How do you implement real-time listeners in Firestore?

Use onSnapshot for real-time updates:

onSnapshot(doc(db, 'users', 'docId'), (doc) => {
  console.log('Current data: ', doc.data());
});

[5]

14. What is denormalization in Firestore?

Denormalization stores duplicated data across multiple documents to optimize read performance. Instead of deep nesting, duplicate key fields across related documents.[2]

15. How would you optimize Firestore queries for performance?

Use indexes for complex queries, limit query results, paginate with startAfter, avoid frequent writes to the same document, and use aggregation queries when available.[2][3]

16. What is Firebase App Check?

App Check verifies requests come from your authentic app using attestation providers (App Attest, Play Integrity, reCAPTCHA) to prevent unauthorized access.[2]

17. How do you add a document to Firestore?

Add a new document to a collection:

await addDoc(collection(db, 'users'), {
  name: 'John Doe',
  email: 'john@example.com'
});

[5]

18. What are composite indexes in Firestore?

Composite indexes allow queries on multiple fields simultaneously (e.g., where city equals “NY” AND age greater than 25). Firestore auto-suggests needed indexes.[2]

19. How do you delete a document from Firestore?

Delete a document using its reference:

await deleteDoc(doc(db, 'users', 'docId'));

[5]

20. Explain fan-out pattern in Firebase databases.

Fan-out duplicates data across multiple paths for efficient querying. Example: Store post ID in both /posts/$postId and /users/$uid/posts array.[2]

Advanced Firebase Interview Questions (21-30)

21. When would you choose Firestore over Realtime Database?

Choose Firestore for complex queries, offline support, better scalability, document-based model. Use Realtime Database for simple JSON tree needs and legacy projects.[2]

22. How do you implement search functionality with Firestore?

Trigger Cloud Function on Firestore writes to sync data to external search service (Algolia/ElasticSearch). Client queries search service, then fetches full docs from Firestore.[2]

23. What are Firebase callable functions and how do you handle their errors?

Callable functions provide RPC-style endpoints. Handle errors by throwing HttpsError with proper codes, implement client-side exponential backoff, ensure idempotency.[1]

24. How do you ensure data integrity in Firestore?

Use security rules for validation, transactions for atomic operations, batched writes for multiple updates, and Cloud Functions for complex business logic enforcement.[3]

25. Explain Firebase Performance Monitoring.

Automatically tracks app start time, network requests, screen rendering. Add custom traces using trace() for specific code sections and analyze in Firebase console.[1]

26. How would you handle data synchronization between multiple Firestore databases?

Use Cloud Functions triggered on writes in source database to replicate data to target databases via Admin SDK, ensuring conflict resolution logic.[3]

27. What are Firebase Hosting rewrite rules?

Rewrite rules route URLs to specific functions or SPAs. Example: Route all paths to /index.html for single-page apps while serving APIs separately.[1]

28. How do you implement role-based access control in Firebase?

Set custom claims like {role: 'admin'} via Admin SDK. Use in security rules: allow write: if request.auth.token.role == 'admin';[2]

29. What strategies optimize Firestore for scalability?

Shard collections across multiple paths, use FieldValue.arrayUnion for counters, implement proper indexing, limit document sizes, use aggregation pipelines.[3]

30. How do you troubleshoot Firebase Functions timeout issues at a company like Atlassian?

Increase timeout settings, optimize cold starts with minimum instances, implement async/await properly, use Cloud Functions Insights for monitoring, and profile expensive operations.[1]

Leave a Reply

Your email address will not be published. Required fields are marked *