adaptive.run TECH BLOG

Cloud can be tricky sometimes. Find out what scenarios we've ran into that are worth being mentioned and explained.

Stateless vs. Stateful Apps in Azure App Service

Level: 100
Publishing date: 26-Dec-2023
Author: Catalin Popa


Introduction:

Azure App Service stands as a powerful platform, facilitating the seamless creation of web and mobile applications tailored for various platforms and devices. One of the crucial distinctions within the realm of app development lies in the architecture of stateless and stateful applications. In this article, we delve into the nuances of stateless and stateful apps in Azure App Service, shedding light on their implications and the significance of ARR affinity.

Stateful Service Dynamics:

A stateful service, by definition, relies on existing data, implying that it possesses memory. Its output isn't solely a function of the input; rather, it hinges on the ability to retain and access stored information over a specific duration. In the context of Azure App Service, understanding the stateful nature of a service becomes integral to crafting robust and efficient applications.

Stateless Service Dynamics:

In contrast to stateful services, stateless services operate without relying on stored data over time. These services treat each request independently, ensuring that the output is solely a function of the input at that moment. Stateless applications maintain no memory of past interactions, contributing to a more scalable and efficient model.

Azure App Service Overview:

Azure App Service provides a comprehensive platform for the development and deployment of enterprise-ready web and mobile applications. Built to cater to diverse platforms and devices, this service operates on a scalable cloud infrastructure, ensuring flexibility and efficiency in application deployment.

Understanding ARR Affinity:

ARR (Application Request Routing) affinity plays a pivotal role in managing user sessions within Azure WebApps. It achieves this by assigning users a special cookie, known as an affinity cookie. This cookie serves as a marker, allowing the service to direct subsequent requests from the user to the same instance they initially interacted with. In essence, ARR Affinity ties a client to a specific web worker for the duration of their session.


azure.microsoft.com

By default, Azure WebApps have ARR Affinity cookies enabled. While this may seem beneficial, especially in scenarios where a client's requests need to be consistently handled by the same server, it poses challenges in a scaled environment. In situations where the application spans multiple instances to handle increased load, ARR Affinity cookies become bound to specific servers, hindering the advantages of a stateless platform.

Disabling ARR Cookies:

Disabling ARR cookies emerges as a strategic solution to challenges associated with ARR Affinity in scaled environments. In this context, where applications are distributed across multiple instances, ARR cookies can inadvertently create dependencies with specific worker machines. Disabling these cookies is particularly advisable for applications designed with load balancing in mind, emphasizing a stateless architecture.

Furthermore, disabling ARR cookies holds relevance in ensuring compatibility with legacy applications. Applications that were not initially designed with load balancing considerations might encounter issues in a scaled environment where ARR cookies establish associations with individual servers.

Conclusion:

In the dynamic landscape of Azure App Service, the choice between stateless and stateful architectures carries profound implications for application behavior and scalability. Understanding the role of ARR Affinity, along with the option to disable ARR cookies, empowers developers to make informed decisions based on the specific requirements of their applications. Whether opting for stateful or stateless design, Azure App Service stands as a versatile platform accommodating diverse application architectures with efficiency and scalability at its core.


adaptive.run

Transform your business.
Run adaptive.

Contact

Phone: +40 72 444 3842
Email: hello@adaptive.run

© Copyright  2019-2024 adaptive.run- All Rights Reserved