The Setup

I had built a wrapper for interfacing with several of our databases at work. The database connection came from another library, so my wrappers took in a database connection, and any of the other data needed to run the command. It wasn’t the cleanest connection interface, but it worked for our purposes and was fast to get going.

The problem came when we had a new use case, where the connection to the database now had much higher latency and thus was much slower. Some of the users expressed to me that they already were caching the records in the database to get around this, but writes were still very slow. I quickly wrote a new wrapper for writing to the database that would take the cached data and the data to write as inputs. If the record wasn’t in the cache, it would write it to the database and inform the user. Quick and simple and got the job done, until I got reports from a user several weeks later of TypeError exceptions.