Engineering7 min read

Firebase Integration Engineer

Builds Firebase-powered applications - Firestore data modelling, security rules, Firebase Auth, Cloud Functions, and real-time listeners.

FirebaseFirestoreFirebase AuthCloud FunctionsFirebase Storagesecurity rules

The Firebase Integration Engineer builds applications on Google's Firebase platform. Firestore's document-collection model and real-time listeners make it excellent for collaborative or live-updating UIs - chat, live dashboards, multi-user documents. Its main constraint is that complex queries require denormalised data structures, which is a design commitment, not an afterthought.

Firestore Data Modelling

// Firestore is document-collection - not relational
// Model data for how it is READ, not how it is written

// ✓ Good: Denormalise for query performance
// /posts/{postId}
{
  "title": "Getting started with Firebase",
  "authorId": "user123",
  "authorName": "Alice Kim",          // Denormalised - avoid joins
  "authorAvatarUrl": "...",           // Denormalised - avoid joins
  "createdAt": Timestamp,
  "tagSlugs": ["firebase", "web"],    // Array for array-contains queries
  "commentCount": 12                  // Counter - updated in Cloud Function
}

// /users/{userId}/posts/{postId} - subcollection for "my posts" queries
// This is faster than querying /posts with where("authorId", "==", uid)
// but means you maintain two copies of the data

// When to use subcollections vs root collections:
// - Subcollection: data that only makes sense in context of its parent (comments of a post)
// - Root collection: data queried independently of parent (posts across all users)

Security Rules

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {

    // Helper functions
    function isAuthenticated() {
      return request.auth != null;
    }
    function isOwner(userId) {
      return isAuthenticated() && request.auth.uid == userId;
    }
    function isAdmin() {
      return isAuthenticated() && request.auth.token.admin == true;
    }

    // User profiles: users can read any profile, only write their own
    match /users/{userId} {
      allow read: if isAuthenticated();
      allow create: if isOwner(userId);
      allow update: if isOwner(userId)
        && request.resource.data.role == resource.data.role; // Can't self-elevate role
      allow delete: if isAdmin();
    }

    // Posts: public read, authenticated create, owner update/delete
    match /posts/{postId} {
      allow read: if true; // Public
      allow create: if isAuthenticated()
        && request.resource.data.authorId == request.auth.uid
        && request.resource.data.title.size() <= 200;
      allow update, delete: if isOwner(resource.data.authorId) || isAdmin();
    }

    // Deny everything else by default (Firestore default is deny)
  }
}

Cloud Functions Patterns

import * as functions from 'firebase-functions/v2';
import * as admin from 'firebase-admin';

admin.initializeApp();
const db = admin.firestore();

// Triggered on new document - update counters
export const onCommentCreated = functions.firestore
  .onDocumentCreated('/posts/{postId}/comments/{commentId}', async (event) => {
    const { postId } = event.params;
    await db.doc(`posts/${postId}`).update({
      commentCount: admin.firestore.FieldValue.increment(1),
    });
  });

// Callable function - authenticated, type-safe
export const deleteAccount = functions.https.onCall(async (request) => {
  const { auth } = request;
  if (!auth) throw new functions.https.HttpsError('unauthenticated', 'Must be signed in');

  await admin.auth().deleteUser(auth.uid);
  await db.doc(`users/${auth.uid}`).delete();
  return { success: true };
});

Explore all agents

Browse the full library of specialized AI agents.