djangohttpfastcgiscgi

Why do web frameworks serve via FastCGI/SCGI, rather than HTTP?


Major web frameworks (such as Django, Pyramid, Rails, etc) are often run as persistent servers, with a separate web server like nginx serving as a frontend. The web server connects via a protocol like FastCGI or SCGI:

browser --[http]--> nginx --[fastcgi]--> flup -> django

This seems convoluted to me; why is the request converted to an entirely different protocol, when the backend could just run its own HTTP server?

browser --[http]--> nginx --[http]--> wsgiref -> django

This approach appears to be both simpler and more flexible, since there's only one transport protocol and it's an RFC.

However, I don't think I've ever seen a web framework encourage the http-only design, so I assume there must be a reason for it.

What are the advantages of using a protocol like FastCGI/SCGI here?


Solution

  • HTTP is a large, complex protocol. Paring the interface down to the capabilities provided by FastCGI or WSGI allows the framework to handle requests faster than if it had to deal with the original.