title: Decoupling MySQL data versus ease of use
body: <p>Assume a simple database for hotel reservations with three tables.</p>
  
  <p><strong>Table 1: Reservations</strong>
  This table contains a check-in and check-out date as well as a reference to one or more rooms and a coupon if applicable.</p>
  
  <p><strong>Table 2: Rooms</strong>
  This table holds the data of all the hotel rooms with prices per night and number of beds.</p>
  
  <p><strong>Table 3: Coupons</strong>
  This table holds the data of all the coupons.</p>
  
  <p><strong>Option #1:</strong>
  If you want to get an overview of the reservations for a particular month with the total cost of each reservation, you'd have to fetch the reservations, the rooms for each reservation, and the coupon (if one is present).</p>
  
  <p>With this data, you can then calculate the total amount for the reservation.</p>
  
  <p><strong>Option #2:</strong>
  However, there is also another option, which is to store the total cost and discount in the reservation table so that it is much easier to fetch these calculations. The downside is that your data becomes much more dependent and much less flexible to work with. What I mean is that you have to manually update the total cost and discount of the reservation table every time you change a room or a coupon that is linked to a reservation.</p>
  
  <p>What is generally recommended in terms of performance (option #2) version data independence (option #1).</p>
  
  <p>UPDATE:
  It is a MySQL database with over 500 000 rows (reservations) at this point, but is growing rapidly. I want to optimize database performance at an early stage to make sure that the UX remains fast and responsive.</p>