Contents

A Serverless TypeScript System

Still Haven't Spent A Penny On This.

The System

What started as a simple TypeScript experiment has turned into something more. I now have the makings of an entire serverless system.

Even better, this whole setup runs on free-tier infrastructure and hasn’t cost a cent to deploy.

Featuring:

  • Container Orchestration
  • Modern Tooling
  • DataDog Metrics (Without a DataDog Agent)
  • Scheduled Cron Tasks
  • Postgres for the data
  • Serverless functions

Although it’s a work-in-progress, it displays how a complex distributed system can be made with modern tooling in a very short amount of time.

Here’s how it works:

  • This site is a static blog hosted on Netlify.
  • A TypeScript API in a Docker Container is hosted with Render.
  • That API interacts with a Postgres database to serve up data.
  • A lightweight Dockerized Data Scraper runs on a schedule and pushes fresh data into Postgres.
  • This site proxies requests from /api/ to the Docker API
  • To avoid cold-start latency (since Render puts free containers to sleep after 15 minutes), a serverless function pings the API periodically to keep it alive.
  • A GitHub Action handles that pinging on a Cron schedule (every 10 min).
  • Request and Response logs from the API are sent to DataDog.

I’ll admit, the dataset isn’t too interesting; it’s basically just Maker, Model, and Part information for assorted heavy construction vehicles. But it could easily be repurposed for data of any sort, and with a little business logic, it can become a full-fledged prototype for a high quality system.

The code repository is here. It uses Prisma as an ORM, Fastify for the API and Cheerio to scrape data. Please note, some portions (proxying and lambdas) live in this website, which does not have a public repo.

Note
This is a work in progress. It was started on 6/17 (AKA Tuesday). The API may be down for enhancements periodically.

It’s simple, scalable, and built entirely with free services.

Although it’s extremely new, very soon it will have:

  • Integration Testing
  • Automatic Test Runs on Deployment
  • Pub/Sub messaging using Redi
  • Local container orchestration via docker-compose Done!
  • Integration with DataDog Done!

Scratch that, a DataDog dashboard is up and running!

The README has all the information necessary to build and run this project. Assuming you know the fundamentals of node and docker

The API

All endpoints return JSON responses and are prefixed from root (/). The full rundown can be viewed in the README on GitHub.

The important endpoints are:


/health

Health check.

GET /makes

Retrieve a list of vehicle makes.

GET /makes/:makeId/models

Retrieve a list of vehicle models by make.

GET /models/:modelId/parts

Retrieve a list of vehicle parts by model.

GET /parts/:partId

Retrieve a part by ID.


Try It Out

You can try out the /makes endpoint here, to fetch out all the known part makers.