Chat Flow
Flow Builder
Blocks
Database
Firebase

Firebase Database Block

What is Firebase?

Firebase is like a smart cloud database that updates in real-time everywhere at once. Built by Google, it's perfect for apps that need live updates - think chat apps, collaborative tools, or any app where users see changes instantly without refreshing the page.

When to Use Firebase

Perfect for:

  • Real-time chat applications
  • Live collaborative tools (like Google Docs)
  • Social media feeds and notifications
  • Live dashboards and monitoring
  • Mobile apps that sync across devices
  • Gaming leaderboards and multiplayer features

Not ideal for:

  • Complex data relationships and joins
  • Advanced querying and analytics
  • Large-scale data warehousing
  • Applications requiring ACID transactions
  • Highly regulated data (some compliance issues)

How It Works

  1. Connect to Firebase: Set up your project credentials
  2. Choose Collection: Select which data collection to work with
  3. Perform Operation: Add, get, update, or delete documents
  4. Real-time Updates: Changes sync instantly across all connected devices

Real-World Examples

💬 Real-Time Chat App

User Sends Message → Add to Firebase → All Users See Message Instantly

Messages appear instantly for everyone in the chat without page refresh

👥 Collaborative Whiteboard

User Draws Line → Update Firebase → All Connected Users See Drawing Live

Multiple users can work on the same document simultaneously

🎮 Live Gaming Leaderboard

Player Scores Points → Update Firebase → Leaderboard Updates for All Players

See rankings change in real-time as players compete

📊 Live Dashboard

New Data Arrives → Firebase Updates → Dashboard Charts Update Automatically

Monitor metrics that update live without manual refresh

Easy Setup Guide

🔌 Step 1: Firebase Project Setup

Get Your Credentials:

  1. Go to Firebase Console (opens in a new tab)
  2. Create or select your project
  3. Go to Project Settings → Service Accounts
  4. Generate new private key (downloads JSON file)

Required Information:

  • Service Account JSON: Complete credentials file from Firebase

⚙️ Step 2: Configure the Block

Connection Settings:

  1. Credentials: Select your Firebase credentials from the dropdown or create new ones
  2. Store Type: Choose between Cloud Firestore or Realtime Database
  3. Operation: Select the action you want to perform

Available Operations:

OperationWhat It Does
GET_DATARetrieve documents/data from Firebase
CREATE_RECORDAdd new documents to your collection
UPDATE_RECORDModify existing documents
DELETE_RECORDRemove documents from your collection

For Cloud Firestore:

  • Collection: The name of your Firestore collection (e.g., "users", "messages")

For Realtime Database:

  • Path: The database path (e.g., "users/123", "chat_rooms/room1")

🎯 Step 3: Operation-Specific Configuration

GET_DATA Operation:

  • Query Conditions: Add field name and value pairs to filter results
    • Field Name: The field to match (e.g., "status")
    • Value: The value to match (e.g., "active")
  • Response Mapping: Map Firebase fields to workflow variables

For Realtime Database GET_DATA:

  • Order By: Field to order results (optional)
  • Limit to First: Get first N records (optional)
  • Limit to Last: Get last N records (optional)

CREATE_RECORD / UPDATE_RECORD Operations:

  • Fields: Add key-value pairs for the data you want to store
    • Key: Field name in Firebase
    • Value: The data to store (can use workflow variables)

UPDATE_RECORD / DELETE_RECORD Operations:

  • Conditions: Specify which documents to update/delete
    • Key: Field to match
    • Value: Value to match

🗂️ Data Structure Example

Collections and Documents:

// Collection: users
{
  "user_123": {
    "name": "John Doe",
    "email": "john@example.com",
    "created_at": "2023-01-15T10:30:00Z",
    "profile": {
      "avatar": "avatar_url",
      "bio": "Software developer"
    }
  }
}
 
// Collection: chat_rooms
{
  "room_456": {
    "name": "General Discussion",
    "created_by": "user_123",
    "members": ["user_123", "user_789"],
    "last_message": "Hello everyone!"
  }
}
 
// Collection: messages
{
  "msg_001": {
    "room_id": "room_456",
    "sender_id": "user_123",
    "text": "Hello everyone!",
    "timestamp": "2023-01-15T14:30:00Z",
    "type": "text"
  }
}

Common Firebase Operations

📝 Creating Data (CREATE_RECORD)

Example: Add New User

  • Store Type: Cloud Firestore
  • Operation: CREATE_RECORD
  • Collection: users
  • Fields:
    • Key: name, Value: {{user_name}}
    • Key: email, Value: {{user_email}}
    • Key: created_at, Value: {{timestamp}}
    • Key: status, Value: active

Example: Add Chat Message

  • Store Type: Cloud Firestore
  • Operation: CREATE_RECORD
  • Collection: messages
  • Fields:
    • Key: chat_room, Value: {{room_id}}
    • Key: sender, Value: {{user_id}}
    • Key: message, Value: {{message_text}}
    • Key: timestamp, Value: {{current_time}}

Example: Create Product Listing

  • Store Type: Cloud Firestore
  • Operation: CREATE_RECORD
  • Collection: products
  • Fields:
    • Key: name, Value: {{product_name}}
    • Key: price, Value: {{price}}
    • Key: category, Value: {{category}}
    • Key: available, Value: true

🔍 Reading Data (GET_DATA)

Example: Get User by Status

  • Store Type: Cloud Firestore
  • Operation: GET_DATA
  • Collection: users
  • Query Conditions:
    • Field Name: status, Value: active
  • Response Mapping:
    • Field Name: name, Variable: Select workflow variable
    • Field Name: email, Variable: Select workflow variable

Example: Get Recent Messages

  • Store Type: Cloud Firestore
  • Operation: GET_DATA
  • Collection: messages
  • Query Conditions:
    • Field Name: chat_room, Value: {{room_id}}

Example: Get Products by Category

  • Store Type: Cloud Firestore
  • Operation: GET_DATA
  • Collection: products
  • Query Conditions:
    • Field Name: category, Value: {{selected_category}}
    • Field Name: available, Value: true

For Realtime Database:

  • Store Type: Realtime Database
  • Operation: GET_DATA
  • Path: users/{{user_id}}
  • Order By: created_at (optional)
  • Limit to First: 20 (optional)

✏️ Updating Data (UPDATE_RECORD)

Example: Update User Profile

  • Store Type: Cloud Firestore
  • Operation: UPDATE_RECORD
  • Collection: users
  • Conditions (to find the document):
    • Key: user_id, Value: {{user_id}}
  • Fields (data to update):
    • Key: last_active, Value: {{current_time}}
    • Key: status, Value: online

Example: Mark Message as Read

  • Store Type: Cloud Firestore
  • Operation: UPDATE_RECORD
  • Collection: messages
  • Conditions:
    • Key: message_id, Value: {{message_id}}
  • Fields:
    • Key: read, Value: true
    • Key: read_at, Value: {{current_time}}

Example: Update Product Availability

  • Store Type: Cloud Firestore
  • Operation: UPDATE_RECORD
  • Collection: products
  • Conditions:
    • Key: product_id, Value: {{product_id}}
  • Fields:
    • Key: available, Value: false
    • Key: sold_to, Value: {{buyer_id}}

🗑️ Deleting Data (DELETE_RECORD)

Example: Delete Old Message

  • Store Type: Cloud Firestore
  • Operation: DELETE_RECORD
  • Collection: messages
  • Conditions:
    • Key: message_id, Value: {{message_id}}

Example: Remove User Account

  • Store Type: Cloud Firestore
  • Operation: DELETE_RECORD
  • Collection: users
  • Conditions:
    • Key: user_id, Value: {{user_id}}

Working with Real-Time Features

🔴 Live Chat Implementation

Send Message Workflow:

  1. User types message
  2. Firebase Block Configuration:
    • Store Type: Cloud Firestore
    • Operation: CREATE_RECORD
    • Collection: messages
    • Fields:
      • Key: room_id, Value: {{room_id}}
      • Key: sender, Value: {{user_id}}
      • Key: text, Value: {{message}}
      • Key: timestamp, Value: {{current_time}}
  3. All connected users see message instantly

Listen for New Messages:

  • Store Type: Cloud Firestore
  • Operation: GET_DATA
  • Collection: messages
  • Query Conditions:
    • Field Name: room_id, Value: {{current_room}}
  • Response Mapping: Map messages to workflow variables

👥 User Presence System

User Goes Online:

  • Store Type: Cloud Firestore
  • Operation: UPDATE_RECORD
  • Collection: users
  • Conditions:
    • Key: user_id, Value: {{user_id}}
  • Fields:
    • Key: status, Value: online
    • Key: last_seen, Value: {{current_time}}

User Goes Offline:

  • Store Type: Cloud Firestore
  • Operation: UPDATE_RECORD
  • Collection: users
  • Conditions:
    • Key: user_id, Value: {{user_id}}
  • Fields:
    • Key: status, Value: offline
    • Key: last_seen, Value: {{current_time}}

📊 Live Analytics Dashboard

Update Metrics:

  • Store Type: Cloud Firestore
  • Operation: UPDATE_RECORD
  • Collection: analytics
  • Conditions:
    • Key: metric_name, Value: {{metric_name}}
  • Fields:
    • Key: value, Value: {{new_value}}
    • Key: updated_at, Value: {{current_time}}
    • Key: trend, Value: {{up_or_down}}

Dashboard Auto-Updates:

  • Connect dashboard to Firebase
  • Metrics update automatically when data changes
  • No need to refresh or poll for updates

Security and Rules

🔒 Firebase Security Rules

Basic User Data Protection:

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

Public Read, Authenticated Write:

// Anyone can read products, only authenticated users can write
match /products/{productId} {
  allow read: if true;
  allow write: if request.auth != null;
}

Chat Room Security:

// Only room members can read/write messages
match /messages/{messageId} {
  allow read, write: if request.auth != null && 
    request.auth.uid in resource.data.room_members;
}

Best Practices

For Performance

  • Limit Query Results: Use limit() to avoid loading too much data
  • Use Indexes: Create indexes for complex queries
  • Paginate Large Lists: Load data in chunks
  • Optimize Document Structure: Keep frequently accessed data together

🔒 For Security

  • Set Up Security Rules: Never leave your database open to all
  • Validate Data: Check data on the client AND server
  • Use Authentication: Require users to sign in
  • Audit Access: Monitor who accesses what data

💰 For Cost Management

  • Minimize Reads: Cache data when possible
  • Efficient Queries: Use compound queries instead of multiple simple ones
  • Clean Up Old Data: Delete unused documents
  • Monitor Usage: Keep track of read/write operations

🎯 For Data Organization

  • Flat Structure: Avoid deep nesting in documents
  • Consistent Naming: Use clear, consistent field names
  • Document Size: Keep documents under 1MB
  • Collection Organization: Group related data logically

Common Use Cases

💬 Chat Application

Chat Rooms Setup:

  • Store Type: Cloud Firestore
  • Operation: CREATE_RECORD
  • Collection: chat_rooms
  • Fields:
    • Key: name, Value: General
    • Key: created_at, Value: {{timestamp}}
    • Key: last_activity, Value: {{timestamp}}

Messages Setup:

  • Store Type: Cloud Firestore
  • Operation: CREATE_RECORD
  • Collection: messages
  • Fields:
    • Key: room_id, Value: {{room_id}}
    • Key: sender, Value: {{user_id}}
    • Key: text, Value: Hello world!
    • Key: timestamp, Value: {{timestamp}}
    • Key: type, Value: text

🎮 Gaming Leaderboard

Create Player Entry:

  • Store Type: Cloud Firestore
  • Operation: CREATE_RECORD
  • Collection: leaderboard
  • Fields:
    • Key: username, Value: ProGamer
    • Key: score, Value: 15420
    • Key: level, Value: 25
    • Key: last_played, Value: {{timestamp}}

Query Top Players:

  • Store Type: Cloud Firestore
  • Operation: GET_DATA
  • Collection: leaderboard
  • Query Conditions:
    • Field Name: score, Value: (use for filtering if needed)
  • Note: Sorting by score requires Firestore indexes

📝 Collaborative Notes

Create Document:

  • Store Type: Cloud Firestore
  • Operation: CREATE_RECORD
  • Collection: documents
  • Fields:
    • Key: title, Value: Meeting Notes
    • Key: content, Value: Document content...
    • Key: last_modified, Value: {{timestamp}}
    • Key: version, Value: 1

Track Edits:

  • Store Type: Cloud Firestore
  • Operation: CREATE_RECORD
  • Collection: document_edits
  • Fields:
    • Key: document_id, Value: {{doc_id}}
    • Key: user, Value: {{user_id}}
    • Key: action, Value: insert
    • Key: position, Value: 145
    • Key: text, Value: New text
    • Key: timestamp, Value: {{timestamp}}

Troubleshooting

Connection Issues

Authentication Failed:

  • Check your service account JSON credentials
  • Verify project ID is correct
  • Ensure Firebase project is active

Permission Denied:

  • Review Firebase Security Rules
  • Check if user is authenticated
  • Verify user has required permissions

🔧 Common Problems

Real-time Updates Not Working:

  • Check if you're using real-time listeners
  • Verify network connectivity
  • Check Firebase console for service issues

Slow Queries:

  • Add appropriate indexes
  • Limit query results
  • Optimize document structure
  • Check query complexity

High Costs:

  • Monitor read/write operations
  • Implement caching strategies
  • Clean up unused data
  • Use efficient query patterns

Node Display

The Firebase block shows:

  • Collection Name: Which Firebase collection you're working with
  • Operation Type: GET, SET, UPDATE, DELETE
  • Document Count: Number of documents affected
  • Real-time Status: Whether real-time updates are active
  • Connection Status: Connected, error, or authenticating

Ready to add real-time magic to your workflows? Firebase makes it easy to build apps that update instantly across all devices!

Indite Documentation v1.4.0
PrivacyTermsSupport