## It's HTTP, All The Way Down
Wes Mason
[@1stvamp](http://twitter.com/1stvamp)
[www.serverdensity.com](http://www.serverdensity.com/)
## Who?
- @1stvamp (twitter/github)
- Engineer at ServerDensity
- I release lots of open source code
- Curate [phpweekly.info](http://phpweekly.info/)
## Hyperwhat?
- First version of HTTP implemented by Tim Berners-Lee in 1991
- Expanded by the HTTP WG in '95.
- Very little has changed in **22 years**.
## No really, what?
- Very simple text based protocol
- First part contains metadata (headers)
- Resource centric actions
- Body can contain any kind of encoded data
## What's new?
- HTTP/1.1 (1999) adds some sugar
- New new:
- Server Sent Events
- WebSockets
- New protocols:
- SPDY
- HTTP/2
## A little about our architecture
- Service Orientated
- Each service in it's own codebase
- HTTP APIs
- Their own clusters with load balancers
## Our services
- RESTful
- Stateless
- Mostly thinlayers
- Common documented API
- Callable from frontend
## The web is our API
- Everything does HTTP
- REST is *great* - let's do more of this
- Almost everything can do HTTP *asynchronously*
## Brave New (Async) World
- Longpolling, WebSockets and Server Sent Events
- UIs are **responsive** or go home
- Libraries like socket.io and SockJS make this pretty easy for devs
## Services
- Non-blocking IO
- Both client and server
- Multiple "workers" - scaling
## Frontend
- Several things
- Not polling for updates, "real time"
- Performing backend tasks without blocking the UI
- WebWorkers
## In which Jane clicks a button
$('.button').click(function() {
$.ajax(...);
});
GET /svc/users/:id
Cookie: session=blah
Content-Type: application/json
Accept: ...
### <your application code here>
Content-Type: application/json
Content-Length: 14
X-Barium: foobar
Connection: close
{"foo": "baz"}
## Sockii
* Multiple backend servers
* JavaScript powered frontend
* Authentication/Authorisation?
* Routing?
* Cross domain?
## Add a little barium
* Every external request coming in via sockii gets an `X-Barium` header
* Our client libraries add this header for internal requests
* "Unique" ID (UUID-4)
* Logged
* A single payload going through our alerting system will maintain this ID
* We can query for records matching it
## Skyhooks
* Many tasks running in a cluster, e.g. polling AWS or Rackspace
* Need to get a response back from a task to a connected WebSocket
* Webhooks to the rescue!
##
# import requests, import pymongo
# setup collection etc. etc.
hooks = webhook_collection.find({"account_id": id})
if data and len(data) > 0:
for hook in hooks:
requests.post(hook["url"], data)
## sys.exit(0)
- Code: [github.com/serverdensity](https://github.com/serverdensity)
- Slides: [github.com/1stvamp/atmosphere-2013-talk](https://github.com/1stvamp/atmosphere-2013-talk)
## ^D
- Jonathan "Joff" Oliver: [about.me/joffie](http://about.me/joffie)
- Grab me and say hi `:-)`