Welcome back to another blog post! My team is deep into building our prediction model with two core technologies that we have been using: SQLAlchemy and PostgreSQL. Below, I’ll share why SQLAlchemy has become my favorite tool and why PostgreSQL is a close runner-up (despite some frustrations), and how both are shaping my teams development process.
Love-Hate Relationship: SQLAlchemy & PostgreSQL
SQL-Alchemy is definitely my favorite technology that I have used since beiginging work on this project, as it is an ORM-Object-Relational Mapper-that allows me to work with databases in a Pythonic way (I like Python). Instead of writing raw SQL (Yuck), I get to define classes that map directly to tables in PostgreSQL, which keeps my code cleaner and more maintainable, as well as my sanity maintains for another day. In particular, I love how relationships between tables can be managed straightforwardly once everything is set up correctly.
In contrast PostgreSQL is an incredibly robust and capable, but it can be cumbersome to configure initially. Creating roles, setting permissions, and learning its advanced features (like partitioning, custom data types, etc.) can be overwhelming. Yet, for production-level applications where performance and reliability matter, PostgreSQL really shines, once our team of course has done the legwork to get everything running smoothly.
Challenges and Potential Improvements
While I have been enjoying using SQLAlchemy, the learning curve certainly was steep. Getting sessions, relationship configurations, and some of the more advanced querying patterns took me a while to learn. I would love clearer error messages on models or misconfigured relationships, those cryptic stack traces can be hard to unravel.
With PostgreSQL, I would like a smoother setup process. Perhaps a guided setup wizard to ease the early stage of setting up roles, databases, and security policies.
Learning Curves
The ORM approach in SQLAlchemy was the hardest to get used to for me. Once I got over that learning curve, it has been a huge timesaver. The SQL part of PostgreSQL has been relatively easy. If you know the basics of SQL, then simple queries and CRUD operations are pretty straightforward.
If I Could Start Over
I would have probably started with a simpler database like SQLite, just to prototype quickly. Then at some other point I’d migrate to PostgreSQL for the rich features and scalability. Also, I wish I had used Docker from the very beginning to containerize PostgreSQL. It would have saved me from the hassle of local installations and configuration quirks across different machines.