Presentation “Use of Django at Jolt Online” at Python Ireland

Yesterday I give a talk about the use of Django in my actual position at Jolt Online Gaming. on the Python Ireland group  I talked a little, using one recent system as example, about our production configuration, use of Django on non-typical ways, work with the database and other tools we use related. At least there were a lot of questions and comments and some great conversation afterwards, so I think it was interesting for the people attending…

So there are the slides (in PDF), in case anyone want to take a look at them. I have put some notes.

Use of Django at Jolt Online 14 Apr 2010 low res

Let me know what do you think!

PD: I had to edit a little the presentation…

EDIT: I’ve added the presentation to SlideShare, it looks like this:


Remember to read the notes!

The intelligent solution that turns to be unadequate

Recenlty I asked for advice on StackOverflow with a question related to sorting information on a Django application.

I copy the question here:

I’m trying to do something similar to this, in Django. This is part of the page of Anna:

Pos NickName      Points
--- ---------     ------
1   The best      1000
...
35  Roger         550
36  Anna          545
37  Paul          540

It’s a chart showing the scoring system, and it intends to show the first position, as well as the relative position of the presented player.

Showing the first one it’s easy, as it’s only making a query to the database and extracting the first one:

 best = Score.objects.all().order_by('-points')[0]

But I’m having problems getting the ones close to the presented player (Anna, in this case). I don’t want to go searching through the complete list, as the complete list of players can be quite long.

Maybe there’s a way to know the position a register occupies in an ordered list…

Any ideas on how to achieve it?

Well, I get with a clever solution that was, well, count the number of players with higher number of points than the actual player, so you’ll get the position. It’s definitively more elegant than rendering the complete list and then searching for the position of a particular player.

The problem is that it won’t work when you have several players with exactly the same number of  points. In that case, you’ll end getting the position of the first one with the same number of points, but not necessarily the one you’re looking, so you end with this kinds of tables:

Pos NickName      Points
--- ---------     ------
1   The best      1000
...
35  Roger         545
36  Paul          550
37  Anna          550

Not showing the actual player on the correct place, or even worse…

Pos NickName      Points
--- ---------     ------
1   The best      1000
...
35  Roger         545
36  Paul          550
37  Lucy          550

Not showing the player at all!

To make things worse the order is not always the same, as you have some players with the same number of points and the DB just seems to not return always the same order,  so you need to introduce another element for sorting (the name, for example) to ensure that the ranking is not dancing just because the players have the exact  number of points.

So.. at the end I needed to make a sort using two parameters (points, then name), get the complete list, get the index of the player and do the things the boring way.. Actually it’s working fine and nice, but I wonder if anyone knows a way of getting that avoiding the need of getting the complete list…

Recuperando archivos antiguos

Hace unos dias descubrí que, rebuscando entre los archivos de Internet, podía acceder a mi antiguo blog (llamado como éste), así que he copiado los artículos que he encontrado para tenerlos disponibles…
Son bastante antiguos, y la orientación entonces del blog era bastante distinta, pero igual a alguien le puede resultar interesante… ¡Quien sabe! Es posible que se me haya pasado error al hacer la copia, si es así, por favor decídmelo para intentar arreglarlo.

Los he agrupado en la categoría “Blog antiguo”, en un arranque de originalidad…

People really love RDBMSs

I had this discussion with a friend, helping him with a personal project. It was a software to help with a weekly schedule, so it has some teachers, each ones with a profile, some alumns, each one with a profile, and classes, relating the teachers with the alumns with time and physical place.

My friend has deal work a lot with RBMS and as a DBA, mostly with Oracle and MySQL, and he his quite good at that. He began designing a relational database model, with tables for alumns, teachers, places, etc… He also wanted to learn Python, so he wanted to access the database with SQLAlchemy and installed a MySQL database for development.

This development was intended for a small academy, so it will run on only one computer. There is no need of making some client-server architecture or any concurrency. Just one application you can start, load the data, change it, and then close and store the data for the next time you need to open it again.

So, basically, what you got here it is making some classes to define objects. Those objects with the information, using SQLAlchemy, will be stored on a MySQL database, and accessed just using the SQLAlchemy interface.

To me it’s clearly overdesign.

What it’s the point in store the data on a RDBMS? You don’t need all the good stuff a relational database bring at all. You don’t need transactions as your data is only accesed by one single application. You don’t need to share the data over a network. You don’t have to standarize the data to be accessed from different languages or clients. Or make a clustered database… Sure, relational databases are great and are used in lots of applications, but in this particular one you’r not getting any real advantage in using one. Instead, you’re creating a data model using classes and objects in Python. We only want that information to be persistent, so we can close the application and open it again and have the same data.

The most appropiate tool in this case, for me, it’s just plain serialization. Just generate an object with all the data and pickle it on one file before closing the application. If we need extra care in case of error, just do it each time something changes. If the data is expected to be huge (not on this case), you can do it on different files. The same if you expect a lot of search.

You can argue that , well, the application can grow, and be distributed, and THEN you can use all the fancy MySQL features. And that’s true. So you need to define a data model than THEN can be adapted using SQLAlchemy or other ORM (I really like the Django one). It’s really not so difficult. But complicate your system in advance is something I like to avoid.

I like to think that we should design a data model, and then (and not before) think how to implement this data model on a particular way (memory, files, database, etc… ). Of course a relational database it’s a lot of time the good solution, but it’s not the only one available.

EDITED: After some comments (which I really appreciate), I have to say that I can be really easily convinced to use SQLite. My position was more “I think that pickling the data is enough, but if you feel more confortably, use SQLite. I really think that MySQL it’s too much). My key idea on the post is to discuss that I think that we should think, even for a few seconds, if the use of a RDBMS is appropiate on every design, and consider alternatives… I think that a lot of designs begin with with MySQL ( or worse, with Oracle or MS SQL server) before even think about the data model… The DB should support the data model, not the data model be made to fit the DB…