Table of contents
Fingerprinting ๐พ
Remote Caching ๐
Where did I use it ? ๐ค
These days, the use of mono-repositories has increased drastically, mainly because of the complexities and interdependencies across multiple applications. Firstly, let’s understand what a mono repository is, a mono repository is basically placing a bunch of software products into a single repository (of course, after overcoming the technical challenges of migration :). Companies that adopt this approach experience improved operational efficiency and seamless teamwork. Tech giants such as Facebook, Google, and Airbnb extensively employ mono-repo. ๐
ย
Coming to our main topic, Turbo Repo (acquired by Vercel) has lately been one of the most popular mono repository choices out there because of its unique features like remote caching, content-aware hashing, parallel execution, and many more.
Let’s talk about a few important ones in this article:
ย
Fingerprinting ๐พ
This is one of the concepts that absolutely blew my mind during the live stream๐คฏ
It’s based on the concept that:
ย
“Never recompute things that have already been done before.”
ย
So let’s say we have two different NextJS applications running on a mono repo and we are cold starting the application, so at first we will see a build running for both applications in the terminal when we type the command yarn turbo run build . The fact the UI package won’t be even built because it’s cleverly using next transpile modules which will help in transpiling the UI package by each independent application, so in the UI package we don’t even need to have an internal build which makes it really fast! โก
ย
Now comes an even cooler part, let’s say we delete the .next directories that contain the build of the applications and re-run the command yarn turbo run build, guess what, it completes the task in an astonishing 0.20s, wow!! ๐
ย
So what actually happened was that turborepo took a fingerprint of the entire codebase and it analyzed each package and dependency, it took a snapshot of the universe and checked the cache, if it finds that there is a cache hit then it moves the things to the correct positions. ๐๐ป
ย
Remote Caching ๐
So normal caching wasn’t enough ๐
With turbo-repo, remote caching can be a great tool for teams who are collaborating on a project. Caches in turbo are special, they store the complete artifacts inside them, they are so stable that they are not only limited to being set up on your machine but can be shared across your team and CI, how cool is that!! ๐
This clearly results in faster build times and deployments for the team. ๐
ย
Turbo remembers all the tasks that you or your teammates have done and instead of executing them locally, it can download them from the remote cache, very similar to how the cloud works. ๐๐ปโโ๏ธ
It’s easy to set it up as well with a few lines of commands like npx turbo link which will give you options for teams/team members to choose from for setting up remote cache with. โ๏ธ
ย
Where did I use it ? ๐ค
I have been working as an open-source developer for CodeForGovTech’23 under Sunbird UCI, so I was assigned to publish an npm package for socket connections that can be used by developers, this way I could also reduce the lines of code in my main file as well. ๐
I came across turborepo in the application I was working on, so on exploring it, our use case for making a mono repository was to have packages locally in our repository so that we can make changes to the package locally and import the UI components from there itself, which helped us to have efficient and faster loading times on the website ๐ก
ย
Linking the live stream on TurboRepo:
ย
Hope you found this article useful!โ๐ป