Software is complicated, even for seemingly simple things. Let’s just take something like an upvote on Reddit. You might think that you just write something to give an upvote when someone hits the button, right?
But no, it’s much more complicated. Software will be encapsulated so that each discrete part is done by discrete code, but this also makes it reusable for other things. What does that mean?
Reddit supports both mobile and web based, and they don’t want to write everything twice, so for the webpage and their mobile apps, they would just make a button that can receive a click for the upvote.
This will then call an API to say “X user submitted an upvote on Y post/comment”
This will need to get written to a database, but lots of things you do on Reddit needs to get written to a database, so there will be a separate part that writes to the database.
You don’t want everyone who is accessing Reddit to have to hit that database when they are scrolling, because that would mean millions of database calls as you scroll Reddit just to see all of the upvote and comment counts. So instead, all of this data will be kept in an in-memory cache.
That write to the database will then also need to update that in-memory cache. This will probably be done in another piece of code.
Then the success of this DB write and cache update needs to get sent to the original upvote API.
This will then send something to either the web page or the mobile app to notify it to update the upvote count on their view.
Now, let’s say that someone at Reddit is working on an update to the award system. They make some changes, but it also will affect that database write and the cache update, adding an extra field to all of those. They didn’t realize the upvote API used some of those same modules in its call. This change works perfectly for the award update.
Then there is also how software is tested. Reddit can’t have a group of people testing every possible thing Reddit can do on iPhone, Android and the web with each and every update. Instead most testing is done via code itself. But this means that each step in that above chain is tested separately. And often some of those tests are poorly written, so perhaps the upvote API will only check that the database got updated, but not the cache when a write it done. So even running all of the tests, that passes.
However when the update goes out, now the upvote button API doesn’t work as this change makes it so the upvote API gets an error on the cache update, which reports an error to the API which reports an error to you the user. However it is still kind of working, your upvote did go in, it just didn’t update the cache so your view didn’t get updated. But if there was something else that triggers a cache refresh, then it would refresh from the DB, get the correct value and things then work.
Latest Answers