One project, three different versions, two books and many good people
Ruby, Sinatra, SQLite
Time fly’s. At the time of writing it is already close to 14 years that I wrote a blog about creating a self-contained MVC application. Back then I was using Ruby a lot and with quite some success with Ruby on Rails in one of my projects. For what I had in mind that was a bit of overkill though. My use-case was:
- Once a month, write down the value of my bikes odometer
- Aggregate the monthly mileage (back than, it was commuter-bike and an MTB only)
- Grep pictures from my daily picture blog
I picked Sinatra and that was a excellent choice and I really loved it: I could use DataMapper for my persistence, had a RubyDSL for views, and a clear yet concise and easy to understand MVC separation. Speaking of persistence: I picked one of the most widely used databases in the world, SQLite. I wanted the project to be truly self-contained and the embedded database was the perfect choice.
If you look at the source, “biking.rb”, of this version you’ll notice that the data model hardly changed in 14 years. It consists of
bikes(well, obviously contains the bikes)
milages(yes, typo, 1:n relationship from the
bikes, contains an entry per month per bike, with the absolute value of the odometer of that bike in that month)
assorted_trips(rides I did on rentals etc.)
lent_milages(added in 2021, so that I can track mileages when I lent a bike separately.)
All stats have been derived from those tables in essence.
Java, Spring Boot, H2
I am a Spring user since 2011 or so. Both for hobby projects and at work. Spring is a unicorn project which just came of age and is legally allowed to drink alcohol in the USA: 21 years and still innovating. In early 2014 I heard first of Spring Boot and I think it was love at first sight. It had everything I liked from Ruby on Rails (or Groovy) and that in Java and Spring.
For me, that opened up a whole new world: My blog series Developing a web application with Spring Boot, AngularJS and Java 8 is one of the most read articles on my blog, it got featured several times in This week in Spring and several other sides. It was really the right thing, at the right time, and it all came together: Java 8 (which was a tremendous edition with tons of new features), the way I designed the application as an API based on rest controllers and that I packaged an AngularJS frontend with it.
SQLite didn’t fly well with Java back then, so I went over to H2 Database Engine, keeping the schema as is. Yes, I am that person who ran H2 with persistent disk store in production for close to a decade.
The articles I wrote in 2014 and 2015, the feedback I got from the Spring Team, especially Phil Webb and Stéphane Nicoll and the involvement in the early Pre-1.0 versions changed my trajectory and lead eventually to me writing a book about Spring Boot, the Spring Boot Buch, published in 2018. Through the work in the Spring ecosystem I also got into contact with Oliver and over him to Michael Hunger. That got me eventually to Neo4j, being a full-time maintainer of Spring Data Neo4j.
At the end of 2014 I had the great pleasure to meet Gernot Starke and Peter Hruschka at a seminar and with some of the things described here, this changed trajectory again, in the mid-time but also in the long run. I documented the whole Spring Boot page with arc42 which ended up in a book named arc42 by example which sells till this very day. The original sources of my piece are still in the repo and a rendered version of it is linked below if you can’t afford the book.
Here's the original content that was created directly by the integration tests of the package: biking2, Architecture and API.
Python, Flask, DuckDB
My life’s focussed changed a lot over the last 5 years. First, the whole biking thing escalated “a bit” and then I discovered running. For some time I had “Michael is an athlete (wishful thinking)” to my profile bios. I think that wishful thinking is done. While I still do all the things I tracked on this site as a hobby and not on amateur or pro level, I think I am pretty good at it. And while I do have some writing projects in the pipeline, my time is sadly limited after all. Upgrading to Spring Boot 3 is about time for this site, but I am stuck on some components for which there are no Jakarta EE pendants. I could have just dropped the location features, but than what’s the point in keeping it in the above-mentioned book? My database model and Hibernate 6.x work pretty well together, no issue there. But AngularJS v1 as a UI? How long can I get away with it?
In the end, I don’t feel like upgrading. And keep on maintaining. But I wanted my stats and my sport site.
I am totally in love with DuckDB: It is a fast, embedded OLAP database which can do all the SQL “tricks” and then some. It is my goto tool even for CSV transformation. And again, I could just copy over my schema. Python and Flask: Well, why not? I wanted to do something different for a while now and it reminds me about Sinatra in the best possible way. And: DuckDB has great Python bindings.
For what I had as SQL disguised as jOOQ code in the Spring Boot application (for example this part here that generates a query that computes the monthly and total average over all years and bikes), I created actual views as API.
v_monthly_average for example represents the same query as above.
Of course, the computational complexity did not disappear by magic.
The aggregation of the computed mileage per month is just part of another view that is used in the query.
All interaction from Python are only
FROM xxx queries which makes the actual application really easy to reason about.
I don’t want to maintain a cloud / server / something setup of a software at the moment, but I also didn’t want to mangle any existing static site generator into my use-case. But there’s Frozen Flask, which essentially crawls a Flask application and renders all URLs it finds, ready to be scp’ed somewhere where HTML can be delivered. For adding new data or manipulate existing one I don’t really need a fancy UI, the interaction I need is scripted now with a handful of shell-scripts.
- The database model stood the test of time and while I changed the actual database and the middleware for the 3rd time, it is constant.
- The development of great tools in the last decade is just stellar; I think the first Oracle version I used in early 2000 was less SQL compliant than DuckDB now.
- Standing on the shoulders of giants: Regardless whether it’s Ruby, Java or Python. Of course, they are quite different languages, but apart query languages the ones I really like best.
- Frameworks come and go, but something like Spring and Spring Boot is pretty unique.
- SQL just rocks.
- Doing the right thing at the right time, getting in contact with people: It’s the best of doing things like this silly site in public.
Hat tip to all people explicitly mentioned here. You’re feedback always meant a lot to me, and you helped me along the way to where I am and what I know today.