<p>Does someone have any tips/advice on database design for a web application? The kind of stuff that can save me a lot of time/effort in the future when/if the application I'm working on takes off and starts having a lot of usage.</p>

<p>To be a bit more specific, the application is a strategy game (browser based, just text) that will mostly involve players issuing "orders" that will be stored in the database and processed later, with the results also being stored there (the history of "orders" and the corresponding results will probably get quite big).</p>

<p><strong>Edited to add more details</strong> (as requested):</p>

<p>platform: Django</p>

<p>database engine: I was thinking of using MySQL (unless there's a big advantage in using another)</p>

<p>the schema: all I have now are some Django models, and that's far too much detail to post here. And if I start posting schemas this becomes too specific, and I was looking for general tips. For example, consider that I issue "orders" that will be later processed and return a result that I have to store to display some kind of "history". In this case is it better to have a separate table for the "history" or just one that aggregates both the "orders" and the result? I guess I could cache the "history" table, but this would take more space in the database and also more database operations because I would have to constantly create new rows instead of just altering them in the aggregate table.</p>

[{'answer_id': 47491, 'author': 'Manuel Ferreria', 'author_id': 4749, 'author_profile': 'https://Stackoverflow.com/users/4749', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://en.wikipedia.org/wiki/Database_normalization" rel="nofollow noreferrer">Database Normalization</a>, and a giving a good thought to indexes, are two things that you just can\'t miss. Especially if you consider a game, where SELECTS happen much more frequently than UPDATEs.</p>\n\n<p>For the long run, you should also take a look at <a href="http://www.danga.com/memcached/" rel="nofollow noreferrer">memcached</a>, as database querys can be the bottleneck whenever you have more than a few users.</p>\n'}, {'answer_id': 47501, 'author': 'Xian', 'author_id': 4642, 'author_profile': 'https://Stackoverflow.com/users/4642', 'pm_score': 4, 'selected': True, 'text': "<p>You have probably touched on a much larger issue of designing for high scalability and performance in general.</p>\n\n<p>Essentially, for your database design I would follow good practices such as adding foreign keys and indexes to data you expect to be used frequently, normalise your data by splitting it into smaller tables and identify which data is to be read frequently and which is to be written frequently and optimise.</p>\n\n<p>Much more important than your database design for high performance web applications, is your effective use of caching both at the client level through HTML page caching and at the server level through cached data or serving up static files in place of dynamic files.</p>\n\n<p>The great thing about caching is that it can be added as it is needed, so that when your application does take off then you evolve accordingly.</p>\n\n<p>As far as your historical data is concerned, this is a great thing to cache as you do not expect it to change frequently.  If you wish to produce regular and fairly intensive reports from your data, then it is good practise to put this data into another database so as not to bring your web application to a halt whilst they run.</p>\n\n<p>Of course this kind of optimisation really isn't necessary unless you think your application will warrant it.</p>\n"}, {'answer_id': 47546, 'author': 'Polsonby', 'author_id': 137, 'author_profile': 'https://Stackoverflow.com/users/137', 'pm_score': 1, 'selected': False, 'text': "<p>Why don't you post the schema you have now? It's too broad a question to answer usefully without some detail of what platform and database you're going to use and the table structure you're proposing...</p>\n"}, {'answer_id': 47851, 'author': 'Boiler Bill', 'author_id': 4352, 'author_profile': 'https://Stackoverflow.com/users/4352', 'pm_score': 1, 'selected': False, 'text': '<p>You should <em>denormalize</em> your tables if you find yourself joining 6+ tables in one query to retrieve data for a reporting type web page that will be hit often.  Also, if you use ORM libraries like Hibernate or ActiveRecord make sure to spend some time on the default mappings they generate and the sql that ends up generating.  They tend to be very chatty with the database when you could have achieve the same results with one round trip to the database.</p>\n'}]
['https://Stackoverflow.com/questions/47486', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2841/']