Your Privacy

This site uses cookies to enhance your browsing experience and deliver personalized content. By continuing to use this site, you consent to our use of cookies.
COOKIE POLICY

Achieving Real-Time Functionality in a Web App — the ‘Right’ Way

Achieving Real-Time Functionality in a Web App — the ‘Right’ Way
Back to insights

Today, there are many scenarios in which we expect real-time (or near real-time) functionality from our web applications. Often it is not even a conscious expectation—but instead is a more subtle enrichment of user experience that many take for granted. When I encounter this demand in my web development work, I take a step back to consider the ‘right’ solution for that particular context. This is because there are numerous ways of achieving a real-time experience (or the illusion of it)—be it through programmatically re-executing data queries or by opening a steady two-way data stream via a WebSocket subscription; or anything in between. Making the ‘right’ choice requires that a developer weigh the application’s needs against the performance expenses associated with the various data acquisition methods. 

Perhaps the most straightforward way to keep the client (your users) seamlessly up to date with your backend is through intermittent polling. For example, an investment application might allow its users to track their favorite stock prices by re-executing a query of the stock data every 10 seconds, perhaps even re-rendering some corresponding charts or graphs with that cadence as well. This approach can and does gracefully cover many use cases and provides a predictable, relatively responsive experience. The downside: polling can be expensive—especially when you are repeatedly querying for large, complex objects for which most of the fields change infrequently.  

A more holistic approach to keeping the client in sync with your backend is using a subscription: a means of bidirectional communication that allows information to flow freely without needing to re-query the database. This persistent connection is usually achieved by communicating via WebSocket (WS) rather than the standard HTTP transport. The power of subscriptions lies in their ability to communicate updates to individual fields as they occur in the database. For this reason, the approach proves very efficient in the case of small, incremental changes to large data objects.  In addition to their efficiency, subscriptions bring true real-time functionality to the table. In cases where your application demands new information as soon as it is available (think instant messaging), the subscription approach provides what is perhaps the very best sustained low-latency solution.  

On the other hand, if your application only needs an update every 5 minutes, it is less expensive to re-initiate an HTTP connection with each update than keeping a WS connection open for that duration when no immediate updates are required or available. The decision between the two protocols always includes weighing the two costs in your specific use case. Option one is the cost of keeping an existing WS connection open (in which case the client constantly receives information—albeit only the response data and a very small header). The second option is the cost of establishing a new HTTP connection (which requires that the client send large headers with the request and receive large headers back with the response). Whatever the best solution may be for your web application, adding real-time functionality can significantly enrich your end-user’s experience and inspire confidence in the app.

Digging In

  • Digital Products

    The Growing Importance of Digital Accessibility

    Embracing Digital Accessibility: A Moral and Business Imperative In today’s digital landscape, accessibility has become crucial for businesses and organizations. With increasing awareness and legal requirements, ensuring that digital products are accessible to all users, including those with disabilities, is not just a compliance issue but a moral imperative. At UDig, we champion ADA compliance […]

  • Digital Products

    Unlocking Business Potential: The Power of Custom Application Development

    Like any savvy business leader, you’re likely always on the lookout for tools to give your company a competitive edge. And in doing so, you’ve undoubtedly considered investing in custom application development. But the question is, how do you ensure that such a major investment in a custom web application development provides a strong return on […]

  • Digital Products

    Mastering Legacy Application Modernization: Strategies for Success

    The ironic truth of the business world is that change is the only constant. But this means that failing to keep pace with the competition and its technologies will only end with you falling behind. That’s where legacy application modernization enters the fold. When you modernize legacy applications, your team gains access to new features […]

  • Digital Products

    CTO Confessions Podcast

    In this episode of CTO Confessions, Rob Phillips, the Vice President of Software Engineering at UDig, digs into his journey from a passionate technologist in his youth to a seasoned leader in the tech industry. He shares valuable lessons on transitioning to senior leadership, the importance of understanding and articulating company problems, and the art of empowering teams for high performance.

  • Digital Products

    Navigating the Challenges of On Premise to Cloud Migration

    In today’s rapidly evolving technological landscape, the shift from on premise solutions to cloud-based infrastructure has become a pivotal transformation for organizations seeking to modernize their IT operations. This transition holds the promise of increased agility, cost savings, and enhanced scalability. However, it is not without its set of formidable challenges that organizations must navigate. […]

  • Digital Products

    The Power of Transferrable Skills in Tech Projects

    Every project has its own unique elements that require flexibility to be effective and achieve success. This often requires picking up new pieces of a tech stack, learning a new programming language, or a new project methodology. Fortunately, there are also many transferrable skills that carry over from one project to the next. In my […]