Search code examples
performancehttpnetwork-programmingtcpsystem-design

why they use http in apis (mobile / desktop / web / ...) , isn't http just for web


Essentially, what I'm asking is, why use HTTP for anything when TCP alone could suffice? HTTP operates on top of TCP, so by sticking to TCP alone, you simplify parsing and avoid the added complexity of HTTP.

I came across an article discussing WhatsApp's tech stack, noting their use of HTTP for their mobile app. It immediately occurred to me that sticking solely to TCP could potentially enhance performance.

article : https://intuji.com/whatsapp-tech-stack-explored/


Solution

  • There are many reasons to stick with a technology even if it does not look like the most optimal suited to the problem. At the end it is about weighing advantages against disadvantages.

    As for the advantages:

    • The technology is well established in practice, i.e. in case of HTTP it is well tested set of applications and libraries supporting the protocol, etc.
    • The technology has a clear future, which can clearly be seen by the continuous development of HTTP (i.e. HTTP/1, HTTP/2, now HTTP/3).
    • It is comparably easy to get developers with knowledge of the technology.
    • Specific for HTTP is also that it works well within restricted environments, where firewalls or proxies are common place. Just do something on top of TCP often gets blocked.

    Compared to these advantages the disadvantage of some more overhead is acceptable. Also, if any theoretical performance advantages of a protocol with less overhead are really noticeable in practice is questionable. The network performance is usually dominated by the latency of the link and not by the (small) overhead of the communication protocol.