Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scale Oriented Architecture

Scale Oriented Architecture

This talk looks at the science of building web services, thinking about APIs from their most basic primitives, and the lessons learned at Twilio and Runscope for supporting APIs at massive scale. (Presented at Silicon Valley Code Camp 2013)

Frank Stratton ☺

October 05, 2013
Tweet

More Decks by Frank Stratton ☺

Other Decks in Programming

Transcript

  1. Dashboard Traffic Gateway API Request Vault Identity Eventador Calculon Courier

    Warp Pipe Mission Control Prometheus Vivaldi Passageway
  2. Dashboard Traffic Gateway API Request Vault Identity Eventador Calculon Courier

    Warp Pipe Mission Control Prometheus Vivaldi Passageway
  3. “The largest architectural change we made was to move from

    our monolithic Ruby application to one that is more services oriented.” https://blog.twitter.com/2013/new-tweets-per-second-record-and-how
  4. Scalable Architectures Dashboard Traffic Gateway API Request Vault Identity Dashboard

    Dashboard Dashboard Dashboard Identity Identity Identity Identity Identity Request Vault Request Vault Traffic Gateway Scale Horizontally API API
  5. Scalable Architectures Dashboard Traffic Gateway API Request Vault Identity Dashboard

    Dashboard Dashboard Dashboard Identity Identity Identity Identity Identity Request Vault Request Vault Traffic Gateway Scale Horizontally API API
  6. Scalable Architectures Dashboard Traffic Gateway Request Vault Identity Dashboard Dashboard

    Dashboard Dashboard Identity Identity Identity Identity Identity Request Vault Request Vault Traffic Gateway Fail Independently API API API
  7. Scalable Architectures Fail Independently Request Vault Identity Eventador Calculon Courier

    Warp Pipe Mission Control Prometheus Vivaldi Passageway Dashboard Traffic Gateway API
  8. Dashboard Traffic Gateway API Request Vault Identity Eventador Calculon Courier

    Warp Pipe Mission Control Prometheus Vivaldi Passageway Scalable Teams
  9. Identity GET /teams/<id> PUT /teams/<id> GET /buckets/<id> GET /buckets ...

    Scalable Teams Dashboard Traffic Gateway API Request Vault
  10. GET

  11. PUT

  12. PUT import requests resp = requests.put(“http://127.0.0.1/buckets/1234”, data={ ... }) if

    resp.ok: return resp.json() # else, raise an error?! raise Exception(“Bucket didn’t return 200 OK”)
  13. PUT import requests retries = 3 for i in range(retries):

    resp = requests.put(“http://127.0.0.1/buckets/1234”, data={ ... }) if resp.ok: return resp.json()
  14. Redis as a Queue import redis r = redis.StrictRedis() def

    queue_item(item): r.lpush(“work_queue”, item) def get_item(): return r.rpop(“work_queue”) class Worker(Greenlet): def _run(): while True: item = get_item() if item: # do work else: sleep(1)
  15. Redis as a Queue import redis r = redis.StrictRedis() def

    queue_item(item): r.lpush(“work_queue”, item) def get_item(): return r.rpoplpush( “work_queue”, “in_progress”) def finish_task(item): r.lrem(“in_progress”, 1, item) class Worker(Greenlet): def _run(): while True: item = get_item() if item: # do work, then finish_task(item) else: sleep(1)
  16. Redis as a Queue import redis r = redis.StrictRedis() def

    queue_item(item): r.lpush(“work_queue”, item) def get_item(): return r.rpoplpush( “work_queue”, “in_progress”) def finish_task(item): r.lrem(“in_progress”, 1, item) def cleanup(): items = r.lrange( “in_progress”, 0, -1) r.rpush(“work_queue”, *items) r.delete(“in_progress”)
  17. Redis as a Queue class Worker(Greenlet): def _run(): while True:

    item = get_item() if item: do_work(item) finish_task(item) else: sleep(1) def do_work(item): item[‘formatted_name’] = string.capwords(item[‘name’]) requests.put(“http://my-service/items/item[‘id’]”, data=item)
  18. Dashboard Traffic Gateway API Request Vault Identity Eventador Calculon Courier

    Warp Pipe Mission Control Prometheus Vivaldi Passageway
  19. Dashboard Traffic Gateway API Request Vault Identity Eventador Calculon Courier

    Warp Pipe Mission Control Prometheus Vivaldi Passageway