Last week we talked about user accounts and said that this week weād talk about the new software stack, so letās do that.
On both new and old Cherp, the core technologies are staying roughly the same - we use PHP as the backend language that handles all the server side logic. This interacts with PostgreSQL as our database engine, and Redis acts as a caching layer between the two for information that takes a little while to get but thatās accessed often; things like your unread count, chat status, etc (Coincidentally, this is also the cause of the ghost unread bug - it caches your unread count for 24 hours unless it changes, but grace period and account deletes donāt decrement the counter. More on that in a minute). On the frontend, we currently use React, an abominable monstrosity that weāre glad to be dropping.
Letās talk about PHP first. Cherubplay was originally written in Python, but nobody really knew enough Python to fix that code up when it started breaking. As such, current Cherp uses PHP 7.4. This is about to leave active support meaning itāll be receiving security updates only, meaning that for this rewrite, weāre switching to PHP 8. Right now, weāre coding with 8.0 in mind, but by the time we release, weāll be on 8.1. Itās quite likely that weāll be able to upgrade through all the 8.x versions after this with little issue. On top of PHP, current Cherp uses a microframework called Slim to provide some API routing stuff. For new Cherp, weāre using Laravel, something most PHP developers reading this will be familiar with. Personally, I prefer the older system (albeit with some major code touch ups needed), but thatās because I find MVC as a paradigm overly convoluted for what it does - but given Laravel is extremely widely used, and will make recruiting new devs easier in future, thatās what weāre going with. It gives us a lot of tools to work with, and so far, is making some things easier and some things harder.
React is what you use right now to see the site. Itās awful, and we hate it. Itās a Javascript framework created by Facebook. For the new version, Laravel gives us a set of tools called Blade that lets us write the frontend in PHP. On top of this, thereās also a system called Livewire that weāre adding - this uses Blade as a basis, but adds some fancy dynamism on top so that you can have a similar experience to what you already have with dynamic elements. This way thereās a lot less Javascript involved, which means itāll be easier on your computer and, if youāre one of those users who use mobile, your battery wonāt drain as fast either.
PostgreSQL (or Postgres, nobody can apparently decide how to refer to it) is the database we use. SQL is widely understood at this point by most techy people, but for those unaware, it stands for Structured Query Language. Ignore the people who tell you itās pronounced āsequelā, theyāre wrong and should be shunned (EDITOR'S NOTE: This opinion is incorrect). The most popular databases of this type are Postgres and MySQL (or MariaDB, a fork of MySQL that has a nicer license and which you should really be using instead). MySQL/MariaDB is a lot more popular than Postgres, but Postgres has a lot of extra flexibility. Most people donāt need this, but current Cherp uses Array datatypes. Arrays are very powerful, but - whether itās just because of the way PHP forces you to use them and theyāre better in other languages, or because the datatype itself kinda sucks - theyāre absolutely awful to work with. For the rewrite, weāre keeping Postgres - even without using any of the advanced features, itās powerful and fast, and if you give me 10 minutes alone in a room with it, I can make it do some impressive things. What we are doing is getting rid of arrays, and moving the stuff we use them for into a separate table. Itās one of those things thatās paradoxically both messier and cleaner, but itāll reduce the load on PHP when it has to explode or implode the arrays when pulling/pushing to the database.
Redis is also staying, though exactly how much use itāll get right now is
debatable, and can only be answered once weāve learned a little more about how Laravel handles things. Right now, we use it for login sessions and, as mentioned, caching. For those who donāt know, caching is where you store something that takes a long time to get to a faster place so it can be called faster. For example, letās say I log in for the first time in a while. When I log in, the top bar needs to show how many unread chats I have, so it asks the database to count how many chats have me as a participant. Then, it filters these to find ones where my chat_status is marked āunreadā. Then it gives the count back. Each step of this is slow, and takes time. Itās also something thatās requested on every page load, so rather than do it every time, we put a step in at the beginning and at the end - check Redis first. Redis stores everything in memory using key-value pairs. Redis has up to 16 ādatabasesā - letās say the unread_counts is database 2. So, it tells Redis to check database 2 for a value with key [whatever my user ID is]. If itās there - it just spits the number out. If not, itāll run through the process of asking the database, and when itās done, it gives the number to Redis. Thereās a few other places where this is done, and a few places where the cached number is ignored and forces another database check to refresh it, but broadly speaking, Redis cuts the performance cost of the site to about 20% of what itād otherwise be.
And there we go - a summary of what weāre using, both for the new site and the old one, as well as a little overview of what it does. If youāre in the Cherp Discord server (TT make this a link) (EDITOR'S NOTE: Ok, done), feel free to hop into the coding channel and Iāll answer any more in depth questions you have.