Methods for Reliable Message Delivery for Real-time Apps
Ensuring messages are delivered promptly and accurately in real-time applications is crucial in enhancing user experience and building trust with your users. However, achieving this reliability can be challenging, as many of the issues that come with guaranteeing message delivery are typically beyond the control of real-time messaging systems.
Continue reading to learn more about some of these challenges and some of the methods to help ensure reliable message delivery for your real-time app.
Challenges in Guaranteeing Message Delivery
Reliably delivering messages in real-time applications can be impeded by several challenges, regardless of the platform’s infrastructure and functionality:
Network Instability and Latency: Fluctuations in network quality can cause significant delays or even complete loss of messages as they are delivered. Network congestion, packet loss, and variable latency can disrupt this flow, and high latency can cause messages to arrive out of order, creating bottlenecks.
Device Connectivity Issues: Devices connected to the internet via Wi-Fi or especially through mobile networks can be prone to connectivity issues. Mobile users might have poor signal strength as they move, and devices can be unexpectedly shut down due to battery life or sudden application closure.
Server-Side Limitations and Inefficient Architecture: Servers might experience overloads during peak usage times, leading to performance degradation, especially if the server is not properly architectured to handle the real-time data. If there are no mechanisms in place to retry and retrieve these failed messages, messages can be lost and not delivered in real time.
External Factors: A range of external factors can affect message delivery, often beyond the control of both the real-time platform and its users. Power outages can knock out data centers, and issues with internet service providers (ISPs) can cause significant disruptions to ensure that the messages are delivered.
Methods to Ensure Reliable Message Delivery
Although some of these challenges are completely out of the control of the real-time provider and its users, there are methods that you can use to help improve this message delivery and ensure volumes of messages are delivered.
Add a Sequence Field to Messages
A sequence field ensures the publisher (sender) sends messages slower than the subscriber (receiver) can receive them. It also allows for functionality to help reorder messages on the client side if they arrive out of order, avoiding redundancy.
PubNub’s low latency platform handles this workflow with its Ordered Message Queues, where each message has a unique serial identifier, guaranteeing message order. While clients can define their order sequence number, we offer an automatic identifier that guarantees order (using a timetoken as a serial message ID that is used as queue pointers) ensuring end-to-end message ordering. As solutions scale, so will the number of message queues, but PubNub’s Routing Mesh ensures subscribe API calls will always be directed to the correct backend container; this means we can guarantee that the correct message queue is ready in memory for the subscribing client, boosting performance and ensuring high availability.
Bundling Messages
Bundling messages can optimize delivery reliability by reducing the number of transmissions and minimizing the chance of message loss. Combining multiple messages into a single bundled message before transmission the overhead associated with sending numerous individual messages is reduced.
PubNub’s messaging capabilities support message bundling, allowing developers to group Messages for efficient delivery and better throughput. Additionally, PubNub bundles transactions together, reducing costs by compressing and bundling API requests without impacting performance. By combining multiple Messages into a single transaction, significant cost reductions can be achieved, especially when dealing with small Messages.
Architectural Choices
Message aggregation and sharding can significantly reduce the risk of message loss due to server overloads. Aggregating messages reduces the number of individual message transmissions while sharding distributes the message load across multiple channels or servers. By combining multiple small messages into a single message before transmission and distributing messages based on criteria like user ID or geographical location, the messaging system can handle load balancing more efficiently, allowing for more proper scalability.
Be sure to take a look at our message aggregation and sharding documentation for more information, as well as our architecture recommendations to help improve message delivery.
Auto-Reconnect Systems
When a message fails to deliver, it can be queued for retransmission after a short delay. This ensures that temporary issues, such as network outages, don’t result in permanent message loss. Implementing auto-reconnect logic in the client application allows it to detect disconnections and automatically attempt to reconnect, requesting missed messages from the server upon reconnection.
PubNub’s messaging platform supports this retry logic, allowing developers to configure the number of retry attempts and the delay between them, by retrieving the lost Messages from storage whenever necessary (via message retention).
Synchronous vs Asynchronous Publishing
While asynchronous publishing can improve performance by allowing multiple messages to be sent simultaneously, synchronous publishing ensures that each message is acknowledged before sending the next one, reducing the risk of message loss. While much slower in performance, synchronous publishing involves sending a message and waiting for an acknowledgment from the client before sending the next, ensuring that messages are delivered and acknowledged one at a time.
What’s Next
While ensuring reliable message delivery in real-time applications is challenging, you can implement methods in the design of your app to help improve message delivery reliability. PubNub takes care of all of these methods for you, allowing you to focus on the architecture of your app to provide the best experience for your users.
If you would like to learn more about PubNub, be sure to check out PubNub’s features.
Overview and List of Features
Understand the essential concepts behind every PubNub-powered app in 5 minutes.
Documentation for features and utilizing SDKs
Have any questions or feedback? Feel free to reach out to devrel@pubnub.com at any time.