Build your own turborepo remote cache
Tags: aws, javascript, devtools, vercel
Published: 2021-12-30 18:44:16

---
title: Build your own turborepo remote cache
published: true
date: 2021-12-30 07:00:00 UTC
tags: aws,javascript,devtools,vercel
canonical_url: https://blog.simonireilly.com/posts/turbo-repo-remote-cache
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ff1vl6rc4nmzoaxow1bk.jpg
---

Photo by <a href="https://unsplash.com/@snapsbyclark?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Clark Van Der Beken</a> on <a href="https://unsplash.com/?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>
  

## Turborepo review and remote-caching explained

I have been looking at [turborepo](https://turborepo.org/), the new fast build tool for javascript/typescript monorepos.

Read on for a brief overview of the space, some tools that are also vying for your attention, and a short code example for creating your own remote-cache for turborepo.

## What is turborepo

>Turborepo is a high-performance build system for JavaScript and TypeScript code bases. *[https://turborepo.org/](https://turborepo.org/)*

It's a Golang devtool that uses directed acyclic graph [this module actually](https://github.com/pyr-sh/dag), to accelerate builds with clever caching strategies, and non sequential dependency management.

This DAG space is hotting up, you might know it from [GitLab Aug 2019 release](https://docs.gitlab.com/ee/ci/directed_acyclic_graph/#needs-visualization), and its about ready to burst onto the scene in a big way with [dagger](https://dagger.io/) bringing it to the masses.

Turborepo packages this graph technology up nicely, and succeeds in lowering the barrier to entry, targeting Javascript/Typescript mono-repos and their maintainers. Its been so successful that [vercel scooped it up this month](https://vercel.com/blog/vercel-acquires-turborepo).

There are still more mature tools in this space, [https://nx.dev/ is 4 years old](https://nx.dev/), so there is definitely stiff competition.

So [will turborepo blow up in 2022](https://dev.to/swyx/why-turborepo-will-be-the-first-big-trend-of-2022-4gfj), absolutely it will, it's a smooth developer experience​, with some big name backers.

## Remote caching

Remote caching is just taking some folders stored locally in `./node_modules/.cache/turbo`; creating a zipped tarball (a group of files collected together as one) of those files, and sending it over the wire with a deterministic cache key.

Turborepo itself warns of some dangers when doing this:

> Remote Caching is a ... Make sure you are caching correctly first and double check handling of environment variables. Please also remember Turborepo treats logs as artifacts, so be aware of what you are printing to the console. *[https://turborepo.org/docs/features/remote-caching](https://turborepo.org/docs/features/remote-caching)*

We all can be vulnerable to these kinds of mistakes, like accidentally committing an SSH key or API Key to GitHub etc. The stakes are higher when the tools are less transparent, and turborepo understand this, hence the warning.

### Remote cache options

Vercel are offering free remote caching at the moment. However, turborepo welcomes us to build our own remote caches, and this can be more secure, as you are controlling the location of your cache, and its encryption.

So a quick remote cache can be built with some serverless technologies but there are other implementations here:

- https://github.com/Tapico/tapico-turborepo-remote-cache 
  - Docker hosted, with Google Cloud Storage or AWS S3
- https://github.com/cometkim/turbocache
  - A cloudflare workers implementation, this one is really quite neat, and will be super cost effective

### Make your own remote cache in AWS

AWS is a big cloud, and since it has a unified auth plane (IAM) it can be a secure place to build your dev-tools. We can then use AWS IAM to enable access to the remote cache(s) locally, or in CI, without having a long lived token. But for the time being that is not an option, so consider a custom authorizer, or a JWT authorizer.

I have used simple Auth using a plaintext header, and for simplicity there is no authorizer being used. The source code is here https://github.com/simonireilly/turbo-remote

## Key Takeaways

- Tools implementing DAG's are becoming more common, and easier to interface with as a developer.
- Turborepo is one of these tools, and it does a good job of lowering the barrier to entry.