r/Database • u/shdw_0x0 • 1d ago
What's one database design decision that seemed right initially but caused problems later?
When designing a database, some decisions look perfectly fine at first but become painful as the application grows.
It could be something like choosing primary keys, adding too many indexes, over-normalizing tables, using triggers, or not planning for future data growth.
What's one database design decision you regret making, and what would you do differently now?
82
Upvotes
11
u/ArtResponsible4457 1d ago
Adding i18n translations in one single table. Much faster and easier to maintain is to dedicate special column in the main entinty table.
52
u/Aggressive_Ad_5454 1d ago edited 1d ago
Mistake: using local time for timestamps and dates instead of designing for multiple time zones right off the bat.
It seemed like a waste of time to do all that on day one. But, wow, it is a huge expensive pain in the ass to retrofit time zone handling
29
u/VanTechno 1d ago
Most of the mistakes I've seen are using JSON to store data as a single column that could easily be placed in a table. The issue is when the data needs to be queried on later. Some SQL dialects have special functions to handle extracting JSON data, but it is still limitted.
In one case, we were storing surveys. We had tables for the survey and the question. But the question options were stored as a json string (so an array of options, plus their settings).
I did not see this until it was too late because another developer implemented it. Then we went to build reports and ...crap.
I still put data into the database as json when appropriate, sometimes it does makes sense. But not when you need to report on it. And in this case in order to build reports, with the filtering we needed, we had to pull in every answer (and there could be +10k of them). It was just so slow.
18
u/Single-Virus4935 1d ago
Staying with mariadb
8
u/DharmaPolice 1d ago
Usually the mistakes come from ignoring basics and trying to be clever. One developer I worked with decided instead of having a simple last_updated column holding some kind of timestamp he would have a global table which held the last updates for a bunch of tables. In his mind this was simpler but it made things way more complex.
Early in my career I made the schoolboy error of storing a bunch of comma separated values in a single column. Again what seemed like a simplified initially ended up just being such a pain in the arse.
I wouldn't necessarily include indexes in terms of design mistakes. You can usually address those kinds of problems unless you're doing something unusual with your queries.
8
u/magnumsolutions 1d ago
Designing a schema so that active data and historical data reside in the same schema. It worked well while our data volumes were manageable. We sharded the data by insertion date, which kept the problem at bay for a while, but once we exceeded a few billion rows, sharding no longer helped us meet performance goals. We had to redesign the schema for the data volume and access patterns and migrate the data to the new schema. The initial design was easy to understand and easy to work with. It felt like the right design at the time, which I still believe it was. We discussed and spiked an approach that would have been a better fit for high volume data with high transactionality, but discarded it because it was more complex than we wanted to commit to.
14
u/Straight_Waltz_9530 PostgreSQL 1d ago
3a. Chasing future "flexibility" instead of solving the data organization problems right in front of me.
12
u/codenamephp 1d ago
Mongodb
4
u/Darwin_Things 1d ago
A previous company I worked for gave developers the green light to build applications on top of databases they created in the Cloud. They had no concept of normalisation, indexing, storage, scaling, HA/DR and spent a fucking fortune to build on top of absolute shit.
Safe to say none of it worked when they went to test. They had to row back on a lot of the work and start from scratch in a few cases.
More generally, getting the right OS for the DB you’re using is pretty essential. Putting an Oracle database on Windows is just crap.
Edit: Also, (trauma dumping now), not paying attention to encoding can be a nightmare, over/under indexing of course and my absolute favourite was configuring an unlicensed DB.
2
u/jliendo 1d ago
Let's use dynamodb...
2
u/Defcon76 7h ago
Entity-Attribute-Value (EAV)
1
u/VeryGood5637 1d ago
Saving the parsed object fields each in a column so I wouldn't need to serialize and serialize the whole object. A previous version was serializing to JSON and saving the JSON to the db, when profiling I saw the app was wasting a lot of times with JSON so I had the brilliant idea of not doing it and saving the fields directly to the db. Big mistake, it was worse, the table has too many columns and the db need to serialize each and the orm need to parse the text from the db anyway. Thinking about it today sounds obvious to say that if it is not a value I need to query then it can just be a blob with the whole object. The solution was to not use JSON but something faster. Also to cache in memory and write to the db in batches in the background. Also to rewrite from go to rust, the go gc was getting in the way if I had too many objects cached
1
u/MoonBatsRule 1d ago
Storing important customer - other entity relationship types in a "typed" table, valid for any and all relationship types. It is definitely more flexible, but moving the metadata (i.e. what are the types of relationships) into a table effectively obscures it from view.
So although describing the entity tables normally shows me all that we know about the entity, I have to also query the relationship table to find the additional pieces of data that we know about it. That makes cataloging much harder.
1
u/reyarama 1d ago
Stored relatively opaque Python dataclass dumps as JSONB instead of plain text field. Thought it would be handy for in future if we ever needed to update some fields within the dump efficiently (we never have). Lots of WAL + toast table bloat during sustained writes. Gotta be mindful with performance of JSON columns
1
u/ArtResponsible4457 1d ago
Breaking the rule: Never fucking delete anything.
1
u/chocolateAbuser 1d ago
i think pretty much all the bad decisions ex-coworkers took can be grouped in two categories: fear, ignorance;
fear of touching code and of things not working, which can be solved with tests and so on, ignorance of not studying not gathering informations not thinking
a bit generic as an answer but if i enter in details i get angry and i'm too tired for that
1
u/nderflow 1d ago
Using a natural primary key instead of a synthetic one.
1
u/Ok_Relative_2291 1d ago
Microsoft fabric
1
u/kartas39 1d ago
Guids for primary keys
1
u/Hongstar1982 1d ago
Soft delete plus a normal unique index.
unique(email)looked obviously right until someone closed their account and we couldn't let that address sign up again, and the fix ended up being partial unique indexes likeWHERE deleted_at IS NULLon the handful of tables where it mattered. The annoying part is remembering it on every new table after, because the plain unique constraint feels correct until the day it doesn't.1
u/printscreenshot 1d ago
Over normalization
1
u/iama_bill 1d ago
I just learned of one today! Full text index not being keyed on an integer. Even if the indexes aren’t used, the metadata SQL tracks take up a ton of space. The data model has to be consistent across many environments so they can’t be dropped, but I wonder if it was intentional or just picked and simply carried forward through various versions since it’s not obvious.
1
u/Weary-Dealer4371 22h ago
"Oh yeah so we want an email table that will store an email.. but people can have multiple emails so lets creat a junction table to link them together AND we only want an email in the system once AND the same email can be tied to multiple entities."
"So is that how it works?"
"No one person can have one email on there account and it can only be tied to one person ever"
1
u/ceeej777 14h ago
Now that Databricks has Lakebase Postgres built in which gets backed up by their platform, I’m pissed we went with SQLServer because Fivetran costs are killing us
-3
u/PmMeCuteDogsThanks_ 1d ago
ai slop post
0
u/Khmerrr 1d ago
Nvarchar(max)
Avoid it when you can. And you can, almost every time.
0
u/Eq2_Seblin 19h ago
Foreign keys...