building a scalable system for shipping tracking

100
BUILDING A SCALABLE SYSTEM FOR SHIPPING TRACKING PREMSHREE PILLAI, Sunday, October 5, 14

Upload: premshree-pillai

Post on 27-Nov-2014

724 views

Category:

Technology


2 download

DESCRIPTION

How Etsy tracks millions of packages -- from vendors all over the world using over 100 different shipping providers -- in an efficient and scalable manner. Slides from my talk at WebCamp Zagreb '14.

TRANSCRIPT

Page 1: Building a Scalable System for Shipping Tracking

BUILDING A SCALABLE SYSTEM FOR SHIPPING TRACKING

PREMSHREE PILLAI,

Sunday, October 5, 14

Page 2: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 3: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 4: Building a Scalable System for Shipping Tracking

SR. ENGINEER, SHIPPINGPREVIOUSLY, YAHOO!

@premshree

Sunday, October 5, 14

Page 5: Building a Scalable System for Shipping Tracking

https://www.etsy.com/listing/110699162/seeker-of-happiness-canvas-tote-bag-you

RE-IMAGINE COMMERCEIN WAYS THAT BUILD A MORE FULFILLING AND LASTING WORLD

Sunday, October 5, 14

Page 6: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 7: Building a Scalable System for Shipping Tracking

CLEVELAND, OHIO

https://www.etsy.com/listing/199433520/1893-antique-map-of-cleveland-ohio

Sunday, October 5, 14

Page 8: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 9: Building a Scalable System for Shipping Tracking

HONG KONG

https://www.etsy.com/listing/199835452/hong-kong-china-morning-street-view

Sunday, October 5, 14

Page 10: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 11: Building a Scalable System for Shipping Tracking

MALI PLAC NA TAVANU, ZAGREB

Sunday, October 5, 14

Page 12: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 13: Building a Scalable System for Shipping Tracking

♥ POTTERY

Sunday, October 5, 14

Page 14: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 15: Building a Scalable System for Shipping Tracking

SCOTTSDALE, AZ

Sunday, October 5, 14

Page 16: Building a Scalable System for Shipping Tracking

ANDOVER, MA

Sunday, October 5, 14

Page 17: Building a Scalable System for Shipping Tracking

LEFKIS, GREECE

Sunday, October 5, 14

Page 18: Building a Scalable System for Shipping Tracking

https://www.etsy.com/listing/150742570/white-nesting-bowl-set-modern-ceramic

1 MILLION SELLERS40 MILLION MEMBERS26 MILLION ACTIVE LISTINGS

Sunday, October 5, 14

Page 19: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 20: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 21: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 22: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 23: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 24: Building a Scalable System for Shipping Tracking

Where is myPACKAGE?

https://www.flickr.com/photos/oneeighteen/2597603677

Sunday, October 5, 14

Page 25: Building a Scalable System for Shipping Tracking

Where is myPACKAGE?

https://www.flickr.com/photos/oneeighteen/2597603677

Sunday, October 5, 14

Page 26: Building a Scalable System for Shipping Tracking

IN TRANSIT 200,000+

https://www.etsy.com/listing/153268931/custom-world-map-absract-print-poster

Sunday, October 5, 14

Page 27: Building a Scalable System for Shipping Tracking

OUT FOR DELIVERY 125,000+

https://www.etsy.com/listing/153268931/custom-world-map-absract-print-poster

Sunday, October 5, 14

Page 28: Building a Scalable System for Shipping Tracking

SHIPPING CARRIERS 150+

https://www.etsy.com/listing/153268931/custom-world-map-absract-print-poster

Sunday, October 5, 14

Page 29: Building a Scalable System for Shipping Tracking

SHIPPING CARRIERS

Sunday, October 5, 14

Page 30: Building a Scalable System for Shipping Tracking

FedEx

DHL

USPS

Hrvatska pošta

...

Sunday, October 5, 14

Page 31: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 32: Building a Scalable System for Shipping Tracking

LET’S DIVE IN

Sunday, October 5, 14

Page 33: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 34: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 35: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 36: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 37: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 38: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 39: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 40: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 41: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 42: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 43: Building a Scalable System for Shipping Tracking

tracking_events

Sunday, October 5, 14

Page 44: Building a Scalable System for Shipping Tracking

SHIPPING APIS

Sunday, October 5, 14

Page 45: Building a Scalable System for Shipping Tracking

GET http://production.shippingapis.com/ShippingAPI.dll?API=TrackV2&XML=%3CTrackFieldRequest+USERID%3D%22022XXXXH6696%22%3E%3CTrackID+ID%3D%22LZ13XXX3064US%22%3E%3C%2FTrackID%3E%3C%2FTrackFieldRequest%3E

Sunday, October 5, 14

Page 46: Building a Scalable System for Shipping Tracking

GET http://production.shippingapis.com/ShippingAPI.dll?API=TrackV2&XML=%3CTrackFieldRequest+USERID%3D%22022XXXXH6696%22%3E%3CTrackID+ID%3D%22LZ13XXX3064US%22%3E%3C%2FTrackID%3E%3C%2FTrackFieldRequest%3E

Sunday, October 5, 14

Page 47: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 48: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 49: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 50: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 51: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 52: Building a Scalable System for Shipping Tracking

TRACKING STATES

Sunday, October 5, 14

Page 53: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 54: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 55: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 56: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 57: Building a Scalable System for Shipping Tracking

INFO_RECEIVED

PACKAGE_RECEIVED

IN_TRANSIT

DELAYED

OUT_FOR_DELIVERY

...

DELIVERED

Sunday, October 5, 14

Page 58: Building a Scalable System for Shipping Tracking

STATE MAP

Sunday, October 5, 14

Page 59: Building a Scalable System for Shipping Tracking

INFO_RECEIVED

“acceptance”

“processed at usps origin facility"

“accepted at usps origin sort facility”

“picked up”

Sunday, October 5, 14

Page 60: Building a Scalable System for Shipping Tracking

INFO_RECEIVED

“tendered at fedex office”

“picked up"

“in fedex possession”

Sunday, October 5, 14

Page 61: Building a Scalable System for Shipping Tracking

IN_TRANSIT

“dispatched from usps sort facility”

“sorting complete"

“local holiday - will attempt delivery on next working day”

“customs clearance processing

Sunday, October 5, 14

Page 62: Building a Scalable System for Shipping Tracking

SELECT * FROM trackings WHERE last_access_date < ?

Sunday, October 5, 14

Page 63: Building a Scalable System for Shipping Tracking

SELECT * FROM trackings WHERE last_access_date < ?

Sunday, October 5, 14

Page 64: Building a Scalable System for Shipping Tracking

? = now() - 15

Sunday, October 5, 14

Page 65: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 66: Building a Scalable System for Shipping Tracking

WHAT’S THE PROBLEM?

Sunday, October 5, 14

Page 67: Building a Scalable System for Shipping Tracking

SIZE

Sunday, October 5, 14

Page 68: Building a Scalable System for Shipping Tracking

SELECT * FROM trackings WHERE last_access_date < ? LIMIT ?

Sunday, October 5, 14

Page 69: Building a Scalable System for Shipping Tracking

STRAGGLERS

Sunday, October 5, 14

Page 70: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 71: Building a Scalable System for Shipping Tracking

SHARDING 101

Sunday, October 5, 14

Page 72: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 73: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 74: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 75: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 76: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 77: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 78: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 79: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 80: Building a Scalable System for Shipping Tracking

SELECT * FROM trackings WHERE shard = ? AND last_access_date < ?

Sunday, October 5, 14

Page 81: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 82: Building a Scalable System for Shipping Tracking

QUEUE

Sunday, October 5, 14

Page 83: Building a Scalable System for Shipping Tracking

FAUX QUEUE

Sunday, October 5, 14

Page 84: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 85: Building a Scalable System for Shipping Tracking

QUEUE_3_DAY

QUEUE_1_DAY

QUEUE_3_HOUR

QUEUE_1_HOUR

...

QUEUE_STOPPED

Sunday, October 5, 14

Page 86: Building a Scalable System for Shipping Tracking

QUEUE MAP

Sunday, October 5, 14

Page 87: Building a Scalable System for Shipping Tracking

INFO_RECEIVED => QUEUE_1_DAY

PACKAGE_RECEIVED => QUEUE_1_DAY

IN_TRANSIT => QUEUE_1_DAY

OUT_FOR_DELIVERY => QUEUE_1_HOUR

...

DELIVERED => QUEUE_STOPPED

Sunday, October 5, 14

Page 88: Building a Scalable System for Shipping Tracking

INFO_RECEIVED => QUEUE_3_HOUR

PACKAGE_RECEIVED => QUEUE_3_HOUR

IN_TRANSIT => QUEUE_3_HOUR

OUT_FOR_DELIVERY => QUEUE_1_HOUR

...

DELIVERED => QUEUE_STOPPED

Sunday, October 5, 14

Page 89: Building a Scalable System for Shipping Tracking

QUEUE AGE

Sunday, October 5, 14

Page 90: Building a Scalable System for Shipping Tracking

QUEUE_3_DAY => 1*60*60*24*3

QUEUE_1_DAY => 1*60*60*24

QUEUE_3_HOUR => 3*60*60

QUEUE_1_HOUR => 1*60*60

Sunday, October 5, 14

Page 91: Building a Scalable System for Shipping Tracking

SELECT * FROM trackings WHERE shard = ? AND queue = ? AND last_access_date < ?

Sunday, October 5, 14

Page 92: Building a Scalable System for Shipping Tracking

SELECT * FROM trackings WHERE shard = ? AND queue = ? AND last_access_date < ?

Sunday, October 5, 14

Page 93: Building a Scalable System for Shipping Tracking

last_access_date < time() - age

Sunday, October 5, 14

Page 94: Building a Scalable System for Shipping Tracking

ASYNC

Sunday, October 5, 14

Page 95: Building a Scalable System for Shipping Tracking

Sunday, October 5, 14

Page 96: Building a Scalable System for Shipping Tracking

IN SUMMARY

Sunday, October 5, 14

Page 97: Building a Scalable System for Shipping Tracking

API

STATE MAP

SHARDING

CRON/ASYNC

FAUX-QUEUE

Sunday, October 5, 14

Page 98: Building a Scalable System for Shipping Tracking

https://www.etsy.com/listing/200465416/mustache-card-youre-awesome

Sunday, October 5, 14

Page 99: Building a Scalable System for Shipping Tracking

Hvala!https://www.etsy.com/listing/157215176/croatia-watercolor-painting-art-print

Sunday, October 5, 14

Page 100: Building a Scalable System for Shipping Tracking

https://www.etsy.com/listing/192250796/i-mustache-you-a-question-embroidery-4

Sunday, October 5, 14