London Travel

About

This was done as a learning exercise.

Data is sourced from the TfL API.

Built upon AWS and serverless technologies. Trying to use to services with free tiers so that this costs nothing/extremely little.

  • DynamoDB - NoSQL database
  • Lambda - Serverless compute (all functions written in NodeJS)
  • EventBridge - Event bus
  • S3 - asset storage
  • CloudFront - CDN

Backend journey

An event driven serverless architecture.

  • EventBridge scheduled rule: every 1 minute it calls a Lambda function which pulls the latest statuses from the TfL API. This API data gets returned.
  • EventBridge rule: Upon a successful response from the API checking function above, the data is sent to another Lambda function. This checks against the current database entries and adds to the database if needed. It also marks which ones are current (and these have their own index) for easy pulling by the current view.
  • At the beginning I did then have another EventBridge rule and Lambda function which would invalidate the CloudFront cache just when statuses changed and CloudFront had a long caching time. You only get 1,000 free invalidations a month though and I realised I would soon run out. Now I have CloudFront set to just cache for 1 minute. The assets (.js, .css, favicon etc) still have a long cache time though. More on the frontend journey below.
  • EventBridge rule: Any Lambda errors are sent to EventBridge then to a Lambda which sends messages to Slack for easy monitoring. I also have it send when there are changes. I probably won't need this in the long term but it helps for debugging while developing.

Frontend journey

Built with Remix. A refreshing new framework that I am enjoying a lot. It is SSR (server side rendered) and uses NodeJS/React. It takes you back to the roots of the Web APIs and is performant.

  • S3 static assets: client side .js, .css, favicon etc file are stored on S3 and then cached and served by CloudFront.
  • Lambda function: A Lambda function renders the UI upon request and returns the HTML to CloudFront for it to cache and serve.
  • CloudFront caching: It caches the static assets from S3 for a long time. It caches the Lambda call for the UI response for 1 minute. (See notes above about when I tried to make the caching smart/more efficient but couldn't while keeping costs free/extremely low.)