Implement rate-limiting

http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#rate-limiting
for readability lets break these lines to smaller ones that we can return (continue) early, we a comment above each one to explain the logic.