Some thoughts on software development, management in general and whatever else is on my mind...
Sunday, December 13, 2020
Serverless Nirvana
This year, 2020, I took some well deserved time off from enterprise software. That does not mean, however, that I did not design and code any software. On the contrary!
During our shelter-in-place, my youngest daughter discovered the ancient board game of Mancala, and we started playing this game daily. After a while, we discovered some patterns in the game, which inspired me to start coding a back-tracking algorithm in Python that would be able to play Mancala against me and other members of my household and win (at least some of the time).
After a couple of days of a disciplined test-driven design (TDD), I was already playing against my freshly minted algorithm looking 7 steps ahead on my laptop using a simple command line interface.
Then I figured it would be cool if I could make this available to other members of my family, either to challenge my algorithm, or each other. But I also did not want to permanently dedicate any hardware to support it. Wouldn’t it be nice if this game would be 100% available, scalable to any imaginable number of players, and at the same time easy and affordable to operate?
Having previously used Amazon Web Services (AWS) Lambda Functions and API Gateway, I already knew this was possible for the back-end services. So I used these two serverless technologies to build back-end ReST APIs for playing Mancala, managed via Serverless Application Model (SAM). By leveraging principles of hexagonal architecture, I was able to reuse the Python code that was already supporting the command line interface by simply adding a lambda handler adapter on top of it.
Then I did some more research and found out that it is very much possible to also have the front end be serverless, as long as one uses one of the modern front-end frameworks to build the web client (e.g., React, Angular, or Vue.js) and publishes the front-end via AWS Simple Storage Service (S3).
After some further research, I picked Vue.js because it's the most recent of those three, it seems to be picking up mindshare, it seems to strike a nice balance between design philosophies of React and Angular, and it seems to have optimal start-up and run-time performance. But perhaps most importantly, Vue.js is also being touted as the framework that allows the quickest developer ramp-up of the three. Indeed, within a week, I had already deployed an initial version of the web user interface that allowed me to play against my algorithm.
Once I started using this early version of my web UI, I realized it was important to allow playing a single game over multiple browser sessions, for which I added persistence in DynamoDB (AWS’s no-SQL serverless database), again by adding an adapter in the back-end Python code. That means I could switch to a different data store without any changes to the rest of either front-end (JavaScript), or back-end (Python) code. But considering DynamoDB’s single-digit ms latency (both reading and writing), I doubt I’ll need to switch any time soon.
It took another week (of 2-3 hours of development per day) to implement a few other features (like animation of computer moves, allowing full control over who plays against whom, and listing rules of the game) before I could say that this serverless Mancala was ready to provide some joy not only to me, but to others as well. If you’d like to use it, feel free to do it here.
The link above should work for any modern browser; I’ve tested it both on current versions of Chrome and Edge on Windows, Chrome and Safari on MacOS, as well as Chrome on Android.
My early adopters (i.e., the members of my family) have so far played over 200 games. How much did AWS charge me for hosting those games? Nada! Zip! Zero dollars! All of the services used (S3, Amazon API Gateway, AWS Lambda, Amazon DynamoDB, CloudWatch and CodeCommit - AWS GIT repository storing my source code) are available within the AWS free tier, and so far I have not used more than 1% of their monthly quotas available.
Besides being a lot of fun, this little project of mine has demonstrated that web (or even mobile) applications today can and should be built using managed services (a.k.a. serverless). Using dedicated machines, even if they are virtual and managed by your cloud infrastructure provider is quite obsolete, and extremely non-economic!
Subscribe to:
Comments (Atom)

