arbisoft brand logo
arbisoft brand logo

A Technology Partnership That Goes Beyond Code

  • company logo

    “Arbisoft is an integral part of our team and we probably wouldn't be here today without them. Some of their team has worked with us for 5-8 years and we've built a trusted business relationship. We share successes together.”

    Jake Peters profile picture

    Jake Peters/CEO & Co-Founder, PayPerks

  • company logo

    “They delivered a high-quality product and their customer service was excellent. We’ve had other teams approach us, asking to use it for their own projects”.

    Alice Danon profile picture

    Alice Danon/Project Coordinator, World Bank

1000+Tech Experts

550+Projects Completed

50+Tech Stacks

100+Tech Partnerships

4Global Offices

4.9Clutch Rating

  • company logo

    “Arbisoft has been a valued partner to edX since 2013. We work with their engineers day in and day out to advance the Open edX platform and support our learners across the world.”

    Ed Zarecor profile picture

    Ed Zarecor/Senior Director & Head of Engineering

81.8% NPS78% of our clients believe that Arbisoft is better than most other providers they have worked with.

  • Arbisoft is your one-stop shop when it comes to your eLearning needs. Our Ed-tech services are designed to improve the learning experience and simplify educational operations.

    Companies that we have worked with

    • MIT logo
    • edx logo
    • Philanthropy University logo
    • Ten Marks logo

    • company logo

      “Arbisoft has been a valued partner to edX since 2013. We work with their engineers day in and day out to advance the Open edX platform and support our learners across the world.”

      Ed Zarecor profile picture

      Ed Zarecor/Senior Director & Head of Engineering

  • Get cutting-edge travel tech solutions that cater to your users’ every need. We have been employing the latest technology to build custom travel solutions for our clients since 2007.

    Companies that we have worked with

    • Kayak logo
    • Travelliance logo
    • SastaTicket logo
    • Wanderu logo

    • company logo

      “Arbisoft has been my most trusted technology partner for now over 15 years. Arbisoft has very unique methods of recruiting and training, and the results demonstrate that. They have great teams, great positive attitudes and great communication.”

      Paul English profile picture

      Paul English/Co-Founder, KAYAK

  • As a long-time contributor to the healthcare industry, we have been at the forefront of developing custom healthcare technology solutions that have benefitted millions.

    Companies that we have worked with

    • eHuman logo
    • Reify Health logo

    • company logo

      I wanted to tell you how much I appreciate the work you and your team have been doing of all the overseas teams I've worked with, yours is the most communicative, most responsive and most talented.

      Matt Hasel profile picture

      Matt Hasel/Program Manager, eHuman

  • We take pride in meeting the most complex needs of our clients and developing stellar fintech solutions that deliver the greatest value in every aspect.

    Companies that we have worked with

    • Payperks logo
    • The World Bank logo
    • Lendaid logo

    • company logo

      “Arbisoft is an integral part of our team and we probably wouldn't be here today without them. Some of their team has worked with us for 5-8 years and we've built a trusted business relationship. We share successes together.”

      Jake Peters profile picture

      Jake Peters/CEO & Co-Founder, PayPerks

  • Unlock innovative solutions for your e-commerce business with Arbisoft’s seasoned workforce. Reach out to us with your needs and let’s get to work!

    Companies that we have worked with

    • HyperJar logo
    • Edited logo

    • company logo

      The development team at Arbisoft is very skilled and proactive. They communicate well, raise concerns when they think a development approach wont work and go out of their way to ensure client needs are met.

      Veronika Sonsev profile picture

      Veronika Sonsev/Co-Founder

  • Arbisoft is a holistic technology partner, adept at tailoring solutions that cater to business needs across industries. Partner with us to go from conception to completion!

    Companies that we have worked with

    • Indeed logo
    • Predict.io logo
    • Cerp logo
    • Wigo logo

    • company logo

      “The app has generated significant revenue and received industry awards, which is attributed to Arbisoft’s work. Team members are proactive, collaborative, and responsive”.

      Silvan Rath profile picture

      Silvan Rath/CEO, Predict.io

  • Software Development Outsourcing

    Building your software with our expert team.

  • Dedicated Teams

    Long term, integrated teams for your project success

  • IT Staff Augmentation

    Quick engagement to boost your team.

  • New Venture Partnership

    Collaborative launch for your business success.

Discover More

Hear From Our Clients

  • company logo

    “Arbisoft partnered with Travelliance (TVA) to develop Accounting, Reporting, & Operations solutions. We helped cut downtime to zero, providing 24/7 support, and making sure their database of 7 million users functions smoothly.”

    Dori Hotoran profile picture

    Dori Hotoran/Director Global Operations - Travelliance

  • company logo

    “I couldn’t be more pleased with the Arbisoft team. Their engineering product is top-notch, as is their client relations and account management. From the beginning, they felt like members of our own team—true partners rather than vendors.”

    Diemand-Yauman profile picture

    Diemand-Yauman/CEO, Philanthropy University

  • company logo

    Arbisoft was an invaluable partner in developing TripScanner, as they served as my outsourced website and software development team. Arbisoft did an incredible job, building TripScanner end-to-end, and completing the project on time and within budget at a fraction of the cost of a US-based developer.

    Ethan Laub profile picture

    Ethan Laub/Founder and CEO

Contact Us

Implementing Real-Time Features in Web Apps with WebSockets and Firebase

https://d1foa0aaimjyw4.cloudfront.net/Implementing_Real_Time_Features_in_Web_Apps_with_Web_Sockets_and_Firebase_a61dc24f32.jpg

Why Real-Time Matters?

Real-time communication enhances user experience (UX), and real-time updates on what has happened. You would not want to reload to check if you have received a message right? Or check if you have received any notifications. Following are just a few basic examples of real-time communication:

 

  • Chat Applications: Message b/w users, chatbots, etc.
  • Live notifications: Alerts, Status Updates, etc.

 

Some complex applications for real-time:

 

  • Online Multiplayer Games i.e. Xiangqi chess.
  • Open-telemetry tools i.e. Prometheus, new relics where you get real-time updates on how your application is doing in terms of response time and traffic like RPM (requests per minute).
  • Collaboration Tools: Simultaneous edits in a shared document.
  • IoT Device Dashboards.
  • Real-Time Dashboards and Analytics.

 

Web socket is a persistent, full-duplex communication channel between the client and server. Unlike HTTP, which is request-driven, WebSockets maintain a continuous connection, enabling real-time data exchange.

Choices in WebSocket Libraries

native WebSockets offer direct control, vs libraries like Socket.IO, SockJs offers the following:

 

  • Automatic reconnection.
  • Room-based communication for grouping clients.
  • Compatibility fallbacks (e.g., using polling when WebSockets are unavailable).

 

Firebase for Real-Time Applications

Firebase, Google’s Backend-as-a-Service (BaaS) platform, offers a Realtime Database and Cloud Firestore, both of which support live synchronization of data across devices.

Why Firebase?

  1. Quick integration with mobile and web SDKs.
  2. A million connections can be created simultaneously without any issues.
  3. Ensures data availability even when offline.

Resource

 

Implement a Collaborative Document Editor

Real-time collaboration tools enable multiple users to work on the same document simultaneously. Let's move step-by-step to implement a collaborative document editor using Firebase for data persistence and WebSockets for real-time communication.

 

Why do we need to Combine Firebase and WebSockets?

  • Firebase offers robust data persistence and synchronization across devices, with offline support and security rules.
  • WebSockets provide the possibility of low-latency, event-driven communication for real-time collaboration.
  • Combined together - Firebase guarantees stable and synchronous storage, and WebSockets offers instant updates to connected clients.

 

Features of the Collaborative Editor

  1. Real-time text synchronization across users.
  2. Change tracking with user attribution.
  3. Conflict resolution and offline support.

 

Step-by-Step Implementation

1. Setting Up the Project

Create a New Project Directory

mkdir collaborative-editor
cd collaborative-editor

Initialize a Node.js Project

npm init -y

Install Firebase SDK Inside the project directory:

npm install firebase
npm install -g http-server

Set Up the Directory Structure

mkdir client

 

2. Setting Up Firebase

Create a Firebase Project

 

  • Go to the Firebase Console.
  • Create a new project and enable Realtime Database or Cloud Firestore.

 

Initialize Firebase in Your Project

// client/firebaseConfig.js
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.22.2/firebase-app.js";
import { getDatabase } from "https://www.gstatic.com/firebasejs/9.22.2/firebase-database.js";

const firebaseConfig = {
 apiKey: "YOUR_API_KEY",
 authDomain: "YOUR_PROJECT_ID.firebaseapp.com",
 databaseURL: "https://YOUR_PROJECT_ID.firebaseio.com",
 projectId: "YOUR_PROJECT_ID",
 storageBucket: "YOUR_PROJECT_ID.appspot.com",
 messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
 appId: "YOUR_APP_ID"
};

const app = initializeApp(firebaseConfig);
export const db = getDatabase(app);

 

3. Building the Collaborative Editor Frontend

Create an HTML File Inside the client directory:

<!-- client/index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Collaborative Editor</title>
</head>
<body>
 <textarea id="editor" style="width: 100%; height: 80vh;"></textarea>
 <script src="./index.js" type="module"></script>

</body>
</html>

 

Implement Real-Time Synchronization:

// client/index.js
import { db } from "./firebaseConfig.js";
import {
 ref,
 onValue,
 set,
} from "https://www.gstatic.com/firebasejs/9.22.2/firebase-database.js";

const docRef = ref(db, "documents/doc1");
const textArea = document.getElementById("editor");

// Listen for Firebase updates
onValue(docRef, (snapshot) => {
 const data = snapshot.val();
 if (data && textArea.value !== data.text) {
   textArea.value = data.text;
 }
});

// Save text to Firebase
textArea.addEventListener('input', () => {
 const text = textArea.value;
 set(docRef, { text });
});

 

To run the implementation

cd client
http-server

 

You should be able to do the following at this point.

Firebase collaborative tool demo

 

Let's enhance the UI a little bit and add interesting features.

 

Enhancing the UI

1. Update HTML file

<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">
 <title>Collaborative Editor</title>
 <style>
   body {
     font-family: Arial, sans-serif;
     margin: 0;
     padding: 0;
     display: flex;
     flex-direction: column;
     height: 100vh;
     background-color: #f4f4f9;
   }

   header {
     background-color: #6200ea;
     color: white;
     padding: 1rem;
     text-align: center;
   }

   textarea {
     width: 100%;
     height: calc(80vh - 2rem);
     border: none;
     resize: none;
     padding: 1rem;
     font-size: 1rem;
     background: white;
     box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
     outline: none;
     margin: 1rem auto;
   }

   footer {
     text-align: center;
     padding: 1rem;
     font-size: 0.9rem;
     background-color: #6200ea;
     color: white;
   }

   button {
     margin: 0.5rem;
     padding: 0.5rem 1rem;
     background: #6200ea;
     color: white;
     border: none;
     border-radius: 5px;
     cursor: pointer;
   }

   button:hover {
     background: #3700b3;
   }
 </style>
</head>
<body>
 <header>
   <h1>Collaborative Editor</h1>
 </header>
 <textarea id="editor" placeholder="Start typing..."></textarea>
 <footer>
   <button id="clearButton">Clear</button>
   <button id="exportButton">Export</button>
 </footer>
 <script src="./index.js" type="module"></script>
</body>
</html>

 

2. Update index.js file

 

Clear Text and Export Text

// Clear text for all users
document.getElementById("clearButton").addEventListener("click", () => {
 if (confirm("Are you sure you want to clear the document?")) {
   set(docRef, { text: "" });
 }
});

// Export text to a .txt file
document.getElementById("exportButton").addEventListener("click", () => {
 const text = textArea.value;
 const blob = new Blob([text], { type: "text/plain" });
 const link = document.createElement("a");
 link.href = URL.createObjectURL(blob);
 link.download = "document.txt";
 link.click();
});

 

Add User Presence

Update firebaseConfig.js (new presence logic):

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.22.2/firebase-app.js";
import { getDatabase, ref, onDisconnect, set } from "https://www.gstatic.com/firebasejs/9.22.2/firebase-database.js";

const firebaseConfig = {
 apiKey: "YOUR_API_KEY",
 authDomain: "YOUR_PROJECT_ID.firebaseapp.com",
 databaseURL: "https://YOUR_PROJECT_ID.firebaseio.com",
 projectId: "YOUR_PROJECT_ID",
 storageBucket: "YOUR_PROJECT_ID.appspot.com",
 messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
 appId: "YOUR_APP_ID",
};

const app = initializeApp(firebaseConfig);
const db = getDatabase(app);

// User presence tracking
const userRef = ref(db, "users/" + Math.random().toString(36).substring(2));
set(userRef, true);
onDisconnect(userRef).remove();

export { db };

 

Update index.js:

// Updated imports

import { db } from "./firebaseConfig.js";
import {
 ref,
 onValue,
 set,
 onDisconnect,
 get,
 child,
} from "https://www.gstatic.com/firebasejs/9.22.2/firebase-database.js";

// User presence logic
const usersRef = ref(db, "users");
onValue(usersRef, (snapshot) => {
 const users = snapshot.val() ? Object.keys(snapshot.val()).length : 0;
 document.querySelector("header").innerHTML = `<h1>Collaborative Editor - ${users} Users Online</h1>`;
});

 

Add version History

New database structure:

{
 "documents": {
   "doc1": {
     "text": "Current content",
     "history": {
       "timestamp1": "Previous content",
       "timestamp2": "Another previous content"
     }
   }
 }
}

 

Update index.js:

// Save version history
textArea.addEventListener("input", () => {
 const text = textArea.value;
 const timestamp = Date.now();
 set(docRef, { text });
 set(ref(db, `documents/doc1/history/${timestamp}`), text);
});

// Revert to previous version
function revertToVersion(timestamp) {
 get(child(docRef, `history/${timestamp}`)).then((snapshot) => {
   if (snapshot.exists()) {
     set(docRef, { text: snapshot.val() });
   }
 });
}

 

Finally, here is how your implementation should look and work:
 

 

3. Handling Conflicts and Offline Support

Conflict Resolution

  • Firebase automatically handles most synchronization issues. To further refine:
  • Use timestamps or user IDs to track edits.
  • Implement a merge strategy to reconcile conflicting updates.

 

Offline Mode

  • Firebase automatically queues offline changes and syncs them when the connection is restored.
  • Test offline functionality to ensure a seamless user experience.

 

Best Practices

Security

  • Use Firebase security rules to restrict read/write access.
  • An example rule to allow access only to authenticated users.

 

{
 "rules": {
   "documents": {
     "$docId": {
       ".read": "auth != null",
       ".write": "auth != null"
     }
   }
 }
}

 

Performance Optimization

  • Minimize the size of data synced in real-time.
  • Use database indexing for efficient querying.

 

Testing

  • Simulate multi-user scenarios to test real-time updates.
  • Validate offline support thoroughly.

 

Huwaiza's profile picture
Huwaiza Tahir

I am a software engineer with 5 plus years of experience in development . I am passionate about creating things from scratch. Currently I am working as a software engineer at Arbisoft, where I deliver challenging tasks. I am always looking to learn more and implement cutting edge technologies.

Explore More

Have Questions? Let's Talk.

We have got the answers to your questions.

We recommend using your work email.
What is your budget? *