Skip to main content

Websocket Reliability for Realtime IDV

Ensure robust identity verification with reliable websockets. Learn best practices for handling connections, data consistency, and error recovery in real-time IDV systems.

Websocket Reliability for Realtime IDV

Contents

In this guide

Jump to the part you need.

Websocket Reliability for Realtime IDV

Realtime identity verification (IDV) is becoming increasingly crucial for modern applications. Traditional HTTP polling introduces latency and inefficiency. Websockets offer a persistent, bi-directional communication channel, enabling faster responses and a smoother user experience. However, websockets also introduce new challenges related to reliability and scalability. This post explores best practices for building robust websocket infrastructure specifically for identity verification workflows.

Key Takeaway 1 Websocket connections are stateful, requiring careful management of connection lifecycle and error handling.

Key Takeaway 2 Implementing robust reconnection logic and message queuing is essential for handling intermittent network issues.

Key Takeaway 3 Proper authentication and authorization are vital to secure websocket connections and prevent unauthorized access to sensitive identity data.

Key Takeaway 4 Using a dedicated websocket infrastructure with scaling and monitoring features improves performance and resilience.

Understanding the Challenges of Websocket Reliability

Unlike HTTP, websockets maintain a persistent connection between the client and server. While beneficial for real-time data transfer, this persistence introduces vulnerabilities. Network instability, server outages, or client-side errors can abruptly terminate connections. If not handled correctly, connection loss leads to data inconsistencies, failed verifications, and a poor user experience.

The inherent challenges include:

  • Connection Drops: Network hiccups, firewall rules, or server restarts can cause unexpected disconnections.
  • Message Loss: Packets can be lost in transit due to network congestion or errors.
  • Scalability: Maintaining persistent connections for a large number of concurrent users can strain server resources.
  • State Management: Tracking connection state (e.g., verification stage, user data) is crucial for resuming workflows after a disconnection.

Designing for Resiliency: Connection Management & Reconnection

A core principle of reliable websocket systems is proactive reconnection logic. Clients should automatically attempt to reconnect if a connection is lost. Implement an exponential backoff strategy to avoid overwhelming the server with rapid reconnection attempts.

Example Reconnection Logic (JavaScript):


function connect() {
  const ws = new WebSocket('wss://your-idv-server.com/ws');

  ws.onopen = () => {
    console.log('Connected to websocket');
  };

  ws.onclose = (event) => {
    console.log('Disconnected from websocket:', event.code, event.reason);
    reconnect();
  };

  ws.onerror = (error) => {
    console.error('Websocket error:', error);
  };

  return ws;
}

let reconnectInterval = 1000; // Initial interval (1 second)

function reconnect() {
  setTimeout(() => {
    const ws = connect();
    reconnectInterval *= 2; // Exponential backoff
  }, reconnectInterval);
}

Server-side, implement a mechanism to track active connections. Upon reconnection, the server should be able to identify the user and resume the verification process from where it left off. This requires storing session state (e.g., in Redis or a similar in-memory data store) associated with each websocket connection.

Ensuring Data Integrity: Message Queuing and Acknowledgements

To mitigate message loss, consider using a message queuing system (e.g., RabbitMQ, Kafka) as an intermediary between the client and server. The client publishes messages to the queue, and the server consumes them. This provides a buffer against temporary network disruptions. Implement message acknowledgements to confirm successful delivery and re-transmit lost messages.

Example Message Flow with Queueing:

  1. Client sends verification request to the websocket server.
  2. Server publishes the request to a message queue.
  3. Server begins processing the request.
  4. Server sends acknowledgement (ACK) message back to the client via websocket.
  5. If the client doesn't receive ACK within a timeout, it re-sends the message.

Securing Websocket Connections with Identity Protocols

Security is paramount when dealing with sensitive identity data. Always use WSS (Websocket Secure) to encrypt communication between the client and server. Implement robust authentication and authorization mechanisms to prevent unauthorized access. Consider using JSON Web Tokens (JWTs) to securely transmit user identity information within websocket messages. Properly validate these tokens on the server side.

Beyond basic authentication, consider using OpenID Connect for WebSockets to establish a secure and standardized identity layer for your websocket communication. This allows you to leverage existing identity providers and manage user authentication centrally.

Leveraging Database Systems for State Persistence

While in-memory data stores like Redis are excellent for fast session state management, long-term persistence requires integration with a database system. Use a database to store verification history, audit logs, and user-related data associated with each websocket session. Consider using a NoSQL database like MongoDB for flexible schema and scalability. Ensure proper indexing and query optimization for efficient data retrieval.

How Didit Helps

Didit's identity platform provides a robust and reliable websocket infrastructure for realtime IDV. We handle the complexities of connection management, message queuing, and security, allowing you to focus on building your core application. Our platform includes:

  • Automatic Reconnection: Our SDKs automatically handle reconnection logic with exponential backoff.
  • Message Queuing: Underlying infrastructure utilizes robust queuing systems for data integrity.
  • Secure Communication: WSS encryption and JWT-based authentication ensure secure data transmission.
  • Scalable Architecture: Our platform is designed to handle a large number of concurrent websocket connections.
  • Realtime ID Processing: Leverage our robust ID verification modules via websockets for instant results.

Ready to Get Started?

Ready to build a robust and reliable realtime IDV system? Explore our interactive demo or sign up for a Didit Business Console account to learn more about our platform.

Try it

Try this in the sandbox

Run the check this guide describes, free.

ID Verification

The product this post is about, taken from its topic. Run it free in the sandbox.

$0.15 per checkStart free

Author

Alberto Rosas

Co-founder and CEO

Alberto Rosas

Alberto Rosas

Co-founder and CEO

About Didit

Questions

Blog questions

Who writes the Didit blog?
The Didit team. Guides reviewed by Alberto Rosas, co-founder and CEO, carry his byline. The rest are published as Didit.
Which topics does the blog cover?
Eight topics: ID verification, business verification (KYB), AML, sanctions and compliance, fraud prevention, transaction monitoring and crypto, country guides, agents and developers, and product updates.
Is the blog available in my language?
Yes, in 15 languages: English, Spanish, French, German, Brazilian and European Portuguese, Catalan, Russian, Arabic, Chinese, Japanese, Hindi, Indonesian, Korean and Swahili. Not every post is translated, so each language shows the posts it has.
Where do I find product updates?
In the changelog at /changelog/ and under the Product updates topic.
Are these posts legal advice?
No. Regulation posts explain rules; your legal team decides how they apply.
How do I find posts on one topic?
Open one of the eight topics, or search the blog.
Are posts dated?
Yes. Every post shows when it was published and when it was last updated.
Do posts link to the docs?
Developer posts link to the matching page on docs.didit.me and to the API reference.
Is the blog the same as the docs?
No. The blog explains rules, markets and product changes for a general reader, while docs.didit.me holds the integration guides and the API reference. Developer posts link the matching docs page and the API reference they describe.

Compliance built in

Audited, certified and attested.

We hold the certifications and build each country's rules into your flows, so you can launch anywhere without worrying. Security and Compliance center

  • Regulation encoded into your flows

    Tell us what you do and where. Didit lists the rules that apply to you, with sources, and builds the checks each country needs into one workflow.

  • Ready for AMLR

    Every requirement of the new EU anti-money laundering rules, from checking customers to human review, is already covered by a Didit check.

  • Tested in Spain's Treasury sandbox

    Spain's Treasury published its supervised sandbox report on Didit's NFC plus active liveness onboarding; SEPBLAC took part and valued the added measures positively.

  • Audited, not self-declared

    iBeta Level 1 and Level 2. Liveness tested under ISO/IEC 30107-3.

Compliance assistant

Your obligations · 3 regions

EU · AMLRCustomer due diligence, human reviewCovered
Illinois, Texas, ColoradoExplicit biometric consentCovered
Germany · Youth protectionVerified adults only (JMStV)Covered
Workflow checked. Every obligation is met
  • SOC 2 Type 2
  • ISO 27001
  • iBeta Level 1 and Level 2
  • EU regulator attestation
  • FSM youth protection
  • GDPR
  • EBA remote onboarding
  • MiCA compatible
  • FIDO Alliance member
  • AMLREU AML Regulation ready

Integration · Didit MCP

Run Didit from your own AI agent

Connect Didit to Claude, Cursor, VS Code or ChatGPT and just ask in plain words. Your agent can do anything you can do in the console, with the same permissions you have.

Add to ClaudeChatGPT
Didit Academy · Lesson 04 · Use Didit with MCP
  • Build workflowsDescribe the checks you need. The agent creates and publishes the flow.
  • Run investigationsAsk why a session was declined, review cases, search people and companies.
  • Change rulesCreate payment rules, test them on past data and switch them on.
  • Pull reportsAsk for numbers, exports or the audit log.

Verify your first user today.

Start free

Free sandbox. Credit applies to work-email sign-ups.