Database Design – Storing Translation Data as JSON Column

database-designrelational-database

We're deciding on how to store translations of some descriptions of database items.

We could go the traditional way and keep a translations table (and a language table and an object_translation linking table) OR we thought it might be better to just have a Description column that contains JSON like the following:

{
     "EN": "This is the translation in English",
     "EE" : "See on kirjeldus eesti keeles"
}

Are there any serious downsides as to why we shouldn't use this? (I haven't seen it being used anywhere else)

Best Answer

The obvious downside is that if your database doesn't support query over JSON, and especially indexing over JSON, you may have lower performance performing operations other than "fetch this blob of translations" - especially "fetch only the "EE" translations", or "tell me what doesn't have an "EE" translation.

The key advantage of storing JSON is that you can serve it much faster: key lookup, read column, dump to browser. No need to futz with encoding it to JSON on the fly - you get the same advantage that you do serving pre-compressed static content to clients rather than on-the-fly gzip compression.

You can also balance the two: use the structured model with the link table to preserve query capabilities, but store JSON data to minimize encoding and decoding costs when you send.

Ultimately, it depends on what queries are most and least common in your problem space.

(Oh, and don't forget to think about what happens if two languages get uploaded at the same time, if you pack everything into the one column.)

Related Topic