Friday, November 20, 2009

SPDY Protocol | From


One of the bottlenecks of current HTTP is that it relies solely on multiple connections for concurrency. This causes several problems, including additional round trips for connection setup, slow-start delays, and a constant rationing by the client where it tries to avoid opening too many connections to a single server. HTTP "pipelining" doesn't help, as each connection may be blocked on the request at the head of the line; in addition, many proxies apparently have poor support for pipelining. Applications, in their desire to create many connections, create many sub-domains to work around browser per-domain connection throttling.

SPDY aims to address this and other application-layer problems associated with modern web applications, while requiring little or no change from the perspective of web application writers.

In a nutshell, SPDY adds a framing layer for multiplexing multiple, concurrent streams across a single TCP connection.  The framing layer is optimized for HTTP-like request-response streams.

The SPDY session offers three basic improvements over HTTP:

  • Multiplexed requests. There is no limit to the number of requests that can be issued concurrently over a single SPDY connection.  Because requests are interleaved on a single channel, the efficiency of TCP is much higher.
  • Prioritized requests. Clients can request certain resources to be delivered first.  This avoids the problem of congesting the network channel with non-critical resources when a high-priority request is pending.
  • Compressed headers.  Clients today send a significant amount of redundant data in the form of HTTP headers.  Because a single web page may require 50 or 100 subrequests, this data is significant. Compressing the headers saves a significant amount of latency and bandwidth compared to HTTP.
Note that for the most part, SPDY attempts to preserve the existing semantics of HTTP features.  All features such as cookies, etags, vary headers, content-encoding negotiations, etc work exactly as they do with HTTP; SPDY only replaces the way the data is written to the network.


  • connection: A TCP-level connection between two endpoints.
  • endpoint: Either the client or server of a connection.
  • session: A framed sequence of data chunks. Frames are defined as SPDY frames; see Framing below.
  • stream: A bi-directional flow of bytes across a virtual channel within a SPDY session.

Main differences from HTTP

SPDY is intended to be as compatible as possible with current web-based applications. This means that, from the perspective of the server business logic or application API, nothing has changed. To achieve this, all of the application request and response header semantics are preserved.  SPDY introduces a "session" which resides between the HTTP application layer and the TCP transport to regulate the flow of data. This "session" is akin to an HTTP request-response pair. The following changes represent the differences between SPDY and HTTP:

The request

To initiate a new request, clients first create a new SPDY session.  Once the session is created, the client can create a new SPDY stream to carry the request.  Part of creating the stream is sending the HTTP header block.  The HTTP header block in SPDY is almost unchanged from today's HTTP header block, with the following differences:

  • The first line of the request is unfolded into name/value pairs like other HTTP headers.  The names of the first line fields are method, url, and version.  These keys are required to be present.  The 'url' is the fully-qualified URL, containing protocol, host, port, and path.
  • Duplicate header names are not allowed.
  • Header names are all lowercase.
  • The Connection and Keep-Alive headers are no longer valid and are ignored if present.
  • Clients are assumed to support Accept-Encoding: gzip.  Clients that do not specify any body encodings receive gzip-encoded data from the server.
  • HTTP request headers are compressed.  This is accomplished by compressing all data sent by the client with gzip encoding.
  • The "host" header is ignored.  The host:port portion of the HTTP URL is the definitive host.
  • POST-specific changes:
    • POST requests are expected to contain a data stream as part of the post; see Data flow below.
    • Content-length is only advisory for length (so that progress meters can work).
    • Chunked encoding is no longer valid.
    • The POST data stream is terminated by a zero-length data frame.

The response

When responding to a HTTP request, servers will send data frames using the SPDY stream created by the client.  The response is similar to HTTP/1.1 in that it consists of a header block followed by a body. However, there are a few notable changes:

  • The response status line is unfolded into name/value pairs like other HTTP headers.  The names of the status line are status and version.  These keys are required to be present
  • If the SPDY reply happens before a SYN_STREAM, then it includes parameters that inform the client regarding the request that would have been made to receive this response, by including url and method keys. 
  • All header names must be lowercase.
  • The Connection and Keep-alive response headers are no longer valid.
  • Content-length is only advisory for length.
  • Chunked encoding is no longer valid.
  • Duplicate header names are not allowed.


The first implementation of the SPDY session runs atop TCP, similarly to how HTTP works today. The client is expected to be the TCP connection initiator. Because it runs on TCP, we have a reliable transport. Unlike HTTP, all connections with SPDY are persistent connections. The HTTP connection header does not apply.

For best performance, it is expected that clients will not close open connections until the user navigates away from all web pages referencing a connection, or until the server closes the connection. Servers are encouraged to leave connections open for as long as possible, but can terminate idle connections after some amount of inactivity if necessary.


Once the TCP connection is established, clients and servers exchange framed messages. There are two types of frames: control frames and data frames.  Frames always have a common header which is 8 bytes.

The first bit is a control bit indicating whether a frame is a control frame or data frame. Control frames carry a version number, a frame type, flags, and a length. Data frames contain the stream ID, flags, and the length for the payload carried after the common header. The simple header is designed to make reading and writing of frames easy.

All integer values, included length, version, and type, are in network byte order.  SPDY does not enforce alignment of types in dynamically sized frames.

And More about SPDY :