We help IT Professionals succeed at work.

What is stateful and stateless connection?

Balbir Singh
Balbir Singh asked
on
What is stateful and stateless connection? I got to know TCP is stateful connection while HTTP is stateless. Though HTTP is L7 and TCP is L4 protocol and HTTP in turn uses TCP protocol. So how it is going to work? a stateless protocol over stateful protocol.

so if we need to configure a failover mechanism then which protocol is better? stateful or stateless? I really would like to read more about it on how it works. Thanks!
Comment
Watch Question

David FavorFractional CTO
Distinguished Expert 2019

Commented:
You asked, "if we need to configure a failover mechanism then which protocol is better? stateful or stateless?"

There is no better or worse. There's just a problem set, then how to resolve the problem.

Describe what you're trying to accomplish, as this will determine the tools + designs people will suggest.
stateful protocols are not directly related to failover. stateful applications are.

it merely means the involved parties remember the "state" of the communication meaning a specific sequence will trigger a specific behavior and each request is treated differently based on that state. tcp is stateful because is uses sequence numbers and will trash or reorder out of sequence packets and possibly retransmit lost ones.

http is not ( in itself ) because past requests have no incidence on whatever request is processed at a given point in time.

that said, if you want to do failover in http, notice that most web applications use sessions which makes them stateful, and unless you synchronise those sessions, they may be lost in case of failover. which is acceptable in most cases and can be alleviated in multiple ways in others.

tell us about your project, and i'm pretty sure we'll be able to provide good advise regarding protocols and what is required to make it work, transparently or not.