Migrating to Soketi: Improving Our Real- Time Communication Architecture

Pratik Patel

  1. Mar 17, 2025
  2. 4 min read

Our journey with real-time data communication has evolved significantly. Initially using Flask-SocketIO with Vue, we faced several challenges that led us to seek a more robust solution. After careful evaluation, we chose Soketi, an open-source WebSocket server that has greatly enhanced our real-time capabilities.

The Challenges We Faced

Our Flask application's direct WebSocket handling presented several technical hurdles:

  • Connection Management: Maintaining persistent WebSocket connections proved complex, especially when scaling horizontally.
  • Connection Stability: We experienced frequent connection drops that were difficult to diagnose and resolve.
  • Resource Allocation: Managing WebSocket infrastructure alongside our main application created additional complexity.

These issues led us to search for a more efficient solution.

Why We Chose Soketi

Soketi offered several key advantages:

  • Independent Architecture: Moving WebSocket handling to a dedicated service improved our system's modularity.
  • Developer-Friendly Interface: The intuitive API makes it easy to implement real-time features.
  • Performance: Built for scale, Soketi handles connection management efficiently.

This solution allows us to concentrate on building features while maintaining reliable real-time communication.

Implementation Guide

Here's how to get started with Soketi:

System Requirements

Note: Soketi requires Node.js LTS and is compatible with most modern operating systems except CentOS 7.

For Ubuntu-based systems, install the following dependencies:


apt install -y git python3 gcc build-essential

Basic Setup

Install Soketi through NPM:


npm install -g @soketi/soketi

Launch the server with default settings:


soketi start

The server will run on port 6001 with these default credentials:

  • App ID: app-id
  • App Key: app-key
  • App Secret: app-secret

These credentials are essential for secure communication between your applications.

Production Deployment

For production environments, use PM2 with a custom configuration:


{
  "debug": true,
  "port": 6001,
  "appManager.array.apps": [
      {
          "id": "YOUR_APP_ID",
          "key": "YOUR_APP_KEY",
          "secret": "YOUR_APP_SECRET"
      }
  ]
}

Start the server using:


pm2 start soketi -- start --config=soketi.json

Nginx Configuration

Serving soketi behind a web server such as Nginx can allow you to access the soketi server via a specific hostname, such as socket.example.com. If you wish, you may also choose to allow Nginx to negotiate your SSL connections instead of providing your SSL certificate information to soketi.

An example Nginx configuration is provided below; however, small adjustments may be required or desired for your specific server environment:


server {
    listen 6002 ssl http2;
    listen [::]:6002 ssl http2;
    server_name your-domain.com;
    server_tokens off;
    root /home/forge/default/public;

    # FORGE SSL (DO NOT REMOVE!)
    ssl_certificate /path/to/ssl/certificate.crt;
    ssl_certificate_key /path/to/ssl/key.key;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS_AES_256_GCM_SHA384:TLS-AES-256-GCM-SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS-CHACHA20-POLY1305-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/nginx/dhparams.pem;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        proxy_pass             <http://127.0.0.1:6001>;
        proxy_read_timeout     60;
        proxy_connect_timeout  60;
        proxy_redirect         off;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    access_log off;
    error_log  /var/log/nginx/socket.example.com.log error;
}

Integration Examples

Server-side implementation (Flask):


from pusher import Pusher

pusher = Pusher(
    app_id='YOUR_APP_ID',
    key='YOUR_APP_KEY',
    secret='YOUR_APP_SECRET',
    host='your-domain.com',
    port=443,
    ssl=True,
)

pusher.trigger('channel-name', 'event-name', {'message': 'data'})

Client-side implementation (Vue):


import Pusher from 'pusher-js';

const pusher = new Pusher('YOUR_APP_KEY', {
    wsHost: 'your-domain.com',
    wssPort: 443,
    forceTLS: true,
    enabledTransports: ['ws', 'wss']
});

const channel = pusher.subscribe('channel-name');
channel.bind('event-name', data => {
    // Handle incoming data
});

Conclusion

Moving to Soketi has significantly improved our development process. The separation of WebSocket handling from our main application has reduced complexity and improved reliability. Using JSON configuration and PM2 management makes operations straightforward and maintainable.

Happy Coding…

About Author
Pratik Patel

See What Our Clients Say

Mindgap

Incentius has been a fantastic partner for us. Their strong expertise in technology helped deliver some complex solutions for our customers within challenging timelines. Specific call out to Sujeet and his team who developed custom sales analytics dashboards in SFDC for a SoCal based healthcare diagnostics client of ours. Their professionalism, expertise, and flexibility to adjust to client needs were greatly appreciated. MindGap is excited to continue to work with Incentius and add value to our customers.

Samik Banerjee

Founder & CEO

World at Work

Having worked so closely for half a year on our website project, I wanted to thank Incentius for all your fantastic work and efforts that helped us deliver a truly valuable experience to our WorldatWork members. I am in awe of the skills, passion, patience, and above all, the ownership that you brought to this project every day! I do not say this lightly, but we would not have been able to deliver a flawless product, but for you. I am sure you'll help many organizations and projects as your skills and professionalism are truly amazing.

Shantanu Bayaskar

Senior Project Manager

Gogla

It was a pleasure working with Incentius to build a data collection platform for the off-grid solar sector in India. It is rare to find a team with a combination of good understanding of business as well as great technological know-how. Incentius team has this perfect combination, especially their technical expertise is much appreciated. We had a fantastic time working with their expert team, especially with Amit.

Viraj gada

Gogla

Humblx

Choosing Incentius to work with is one of the decisions we are extremely happy with. It's been a pleasure working with their team. They have been tremendously helpful and efficient through the intense development cycle that we went through recently. The team at Incentius is truly agile and open to a discussion in regards to making tweaks and adding features that may add value to the overall solution. We found them willing to go the extra mile for us and it felt like working with someone who rooted for us to win.

Samir Dayal Singh

CEO Humblx

Transportation & Logistics Consulting Organization

Incentius is very flexible and accommodating to our specific needs as an organization. In a world where approaches and strategies are constantly changing, it is invaluable to have an outsourcer who is able to adjust quickly to shifts in the business environment.

Transportation & Logistics Consulting Organization

Consultant

Mudraksh & McShaw

Incentius was instrumental in bringing the visualization aspect into our investment and trading business. They helped us organize our trading algorithms processing framework, review our backtests and analyze results in an efficient, visual manner.

Priyank Dutt Dwivedi

Mudraksh & McShaw Advisory

Leading Healthcare Consulting Organization

The Incentius resource was highly motivated and developed a complex forecasting model with minimal supervision. He was thorough with quality checks and kept on top of multiple changes.

Leading Healthcare Consulting Organization

Sr. Principal

US Fortune 100 Telecommunications Company

The Incentius resource was highly motivated and developed a complex forecasting model with minimal supervision. He was thorough with quality checks and kept on top of multiple changes.

Incentive Compensation

Sr. Director

Most Read
UX Gamification in Enterprise Software: Boosting Productivity Through Play

In the world of enterprise software, we often focus on making things efficient, functional, and sometimes, well, boring. But what if work didn’t have to feel like work all the time? That’s where gamification comes in. By borrowing elements from games—like points, rewards, and challenges—we can make enterprise tools more engaging and, surprisingly, boost productivity along the way.

Jaskaran Singh

  1. Nov 26, 2024
  2. 4 min read
Generative AI in Data Analytics: Challenges and Benefits

In today's digital era, data is being generated at every turn. Every interaction, transaction, and process creates valuable information, yet transforming this raw data into insights that can drive business decisions remains a significant challenge for many organizations.

Chetan Patel

  1. Nov 22, 2024
  2. 4 min read
Snowflake: A Game-Changer in Cloud Data Warehousing

Snowflake’s cloud data warehousing platform is transforming how businesses manage and analyze their data. With its powerful combination of scalability, efficiency, and affordability, Snowflake empowers organizations to handle large datasets seamlessly. Whether you're working with terabytes or petabytes of data, Snowflake ensures high-performance data processing and analytics, unlocking the full potential of your data.

Vinay Chaudhari

  1. Nov 21, 2024
  2. 4 min read
Building a Simple E-Invoicing Solution with AWS Lambda and Flask

In today’s fast-moving distribution industry, efficiency is everything. Distributors need quick, reliable tools to handle tasks like generating invoices and e-way bills. That’s why we created a serverless e-invoicing solution using AWS Lambda and Flask—keeping things simple, cost-effective, and secure. Here’s how we did it and the benefits it brought to distributors.

Yash Pukale

  1. Nov 13, 2024
  2. 4 min read