distributedsystem/microservice


Stateful Applications

  • Retain information about user interactions and past requests.
  • Server keeps track of the user’s session state, allowing users to pick up where they left off.
  • Examples include online banking and email.
  • Characteristics:
    • Context-aware: Transactions are influenced by prior interactions.
    • Server dependency: Requests are typically processed by the same server.
    • Features tracked: Preferences, recent activity, and window location.
  • Challenges:
    • More complex session management and load balancing.
    • Increased resource utilization for managing session data.
    • Greater risk of session loss if a server fails, unless replicated.

Stateless Applications

  • Do not store information about previous interactions.
  • Treat every transaction as independent and isolated.
  • Examples include online searches and vending machine operations.
  • Characteristics:
    • No context: Each request starts fresh.
    • Server independence: Requests can be handled by any server.
  • Advantages:
    • Simpler development and maintenance.
    • Greater scalability and fault tolerance.
    • Lower resource utilization.

Comparison

  • Scalability: Stateless apps are more scalable due to independent transactions.
  • Fault Tolerance: Stateless apps are less affected by server failures.
  • Complexity: Stateless apps are simpler to develop; stateful apps require careful state management.
  • Resource Use: Stateless apps are more resource-efficient.

State and Containers

  • Containerization:
    • Initially designed for stateless apps, enabling portability and flexibility.
    • Stateful apps are now being containerized for enhanced speed and storage capabilities.
  • Management:
    • Tools like Kubernetes and StatefulSets allow for efficient management of both stateful and stateless containers.
  • Decision Factors:
    • Stateless is ideal for temporary data needs.
    • Stateful is better for apps needing continuity across sessions.