Tech stack of our university graduation project
Intro#
This page starts a short series of blog posts describing my (and my team’s) university graudation project which also has a business potential. These posts will describe our architecture, security model, deployment and other related topics. Core part of this product is RAG system which I’m barely involved so I will leave it as a deliberate gap. For more information about our this project check out the Landing page (only Polish version). More episodes of this series will be tagged with #my-graduation-project (look just below the page title).
There is also a chance that I will reference this post in the final paper that we have to write (it’s kinda the main purpose of this entire series so that it will be easier for me to copy some parts into there lol).
In this specific episode I will describe our chosen tech stack and how we deploy everything.
Client-first approach#
It’s often a good idea to think from the client perspective first and then choose technology stack to pass all criteria of the product. This case was no different. At first we got a suggestion to build an application where companies with mechanics can upload large amount of device documentation and that later those mechanics can reference them from the app on their tablet. As someone may have already spotted it, it’s a RAG system.
Concrete choices#
First, and one of the most important project decisions was chosing a programming language. It’s often said that Python is the best programming language for any kind of AI implementation. Because of that, this because our language of choice. To be honest it was my very first time to use Python for something bigger than for some very trivial scripts and I had to grind learning. At least my other teammates have done some programming in Python so it was still a safe choice, even including a time for me to learn some stuff which was not that hard if we look that I’ve done Elixir and TypeScript backend development.
In this article I’m not going to describe our frontend. I have done a little work on this side but I don’t think it’s important to for this topic. Therefore, I will only talk about the backend.
Then after we knew that we’re going all-in with Python we had to choose a backend framework. Quick research helped us to choose FastAPI. It’s main advantage was at first popularity and large community and learning resources, and second relatively flat learning curve in comparison with for example Django. With FastAPI we could have started implementing our MVP with little-to-none framework knowledge but with general knowledge how backend, REST and networking works in general.
Okay, up to this point we know that we’re going with Python and FastAPI which by the way is nowadays pretty common stack, no?
Next, we needed to think about the way we want to store data. What data are we going to have? Of course something about our users, messages, chat threads, device models that we had, categories of devices - all of these fit nicely into some relational database. I suggested that we will use Postgres just because I have done several projects with it and it’s mostly the default choice now. I believe that choosing something just because something is popular is in most cases a good idea, at least because there are more resources to learn, an in this case that I was already familiar with it.
What do we need to store beyond relational data? Of course we must do it for all instruction documents that users will upload to the application. First thought was that our VPS already has 60GB of disk space so we used the simplest Docker Volume with a directory where we put all user attachments. Here I can shortly tell that it was probably not the best idea and now we’re fighting with the storage and thinking about migration to object storage. Maybe I will write about this migration in another episode once everything is done.
We have chosen our programming language, framework, database and place to store files. But how will there files get there?
I won’t dive that deep into how RAG works because honestly I don’t know it more that at some shallow level but every time user uploads a document it must be processes (a.k.a. ingested) by our server. This can be probably done within a single request but is VEEEERY inconvenient for users to tell them to wait potentially a few minutes without closing their browsers windows until document is ready. And what if more users would like to do it at the same time? Or even a single user would like to ingest multiple files? Catastrophy!
That’s why we had to look for some tool for background processing. Some popular solution in Python world is Celery but it has a downside that requires Redis which complicates our architecture. What I’ve found what I believe in our case is better is Procrastinate. Why is it better for us? Because doesn’t require additional Redis dependency but stores job states in a Postgres table, and the advantage of being able to combine job state update with other data updates in a single transaction.
I think that major parts of our applications are already told here. We have to run:
- a FastAPI process
- a Procrastinate worker process
- a Postgres instance
Someone could think here about using some managed platform like Fly.io, Vercel, or whatever but that’s not the case. These platforms can become too pricey for us and using them can lead to some kind of vendor lock or worse: not being able to do something like we can’t run background worker on serverless platform. We have bought a VPS and deployed everything there. Postgres runs as a system daemon and an application is deployed using Docker Compose. Everything is behind a Caddy web server that takes care about domain certificates from Cloudflare.
Ending words#
That’s roughly our architecture and chosen technologies. There are some other topics that I want to cover in these posts, like for example how Docker container communicates with Postgres (which is not as intuitive as it can be), how we’re going to manage all backups, more details about how we utilize Docker for deployment of multiple parts of this application, probably I will also write about publishing of this app to Google Play which is one of my upcoming responsibilities, and maybe I will ask some of my teammates if I can publish here their perspective, who knows.
Please forgive me my chaotic writing style but I’m new to this blogging “industry” and treat it as a hobby :) Have a nice day!