4 ms·
I really wish developers cared more about normalization and stop shoving everything into a JSON(b) column.
by ellisv 2y ago
I really wish developers cared more about normalization and stop shoving everything into a JSON(b) column.
- devin 2y agoEven if you care about it, you will still often wind up with a junk drawer of JSONB. I don't really see it as a problem unless people are writing bad queries against it instead of lifting values out of the JSONB into their own columns, etc.
- mnahkies 2y agoYeah exactly, and I'll take a JSON(B) column over TEXT with maybe valid serialised JSON, maybe RON, maybe something completely random any day
- randomdata 2y agoMost developers using these kinds of tools these days are actually building their own database management systems, just outsourcing the persistence to another DMBS, so there isn't a strong imperative to think about good design so long as it successfully satisfies the persistence need. Whether we actually should be building DMBSes on top of DMBSes is questionable, but is the current state of affairs regardless.
- tightbookkeeper 2y agoA previous employer thought that sql databases didn’t understand graphs. So they made their own system for serializing/deserializing graphs of objects into Postgres . They never used queries and instead had their own in-memory operators for traversing the graph, had to solve problems like deleting an entry and removing all references, partial graph updates. And I still don’t think it works.
- theamk 2y agoThis needs working schema migration process, including ability to undo schema change if the new column tanks the performance or breaks stuff. If there are CLI tools involved, you also need to ensure you can handle some downtime, or do synchronized version update across company, or support both old and new schemas for a while. If a database is not part of team's primary product all of this could be missing.
- beachy 2y agoLong before databases could even store structured JSON data, junior developers used to bikeshed viciously over the correct degree of normalization. More experienced developers knew that the correct answer was to duplicate nothing (except for keys obviously) and then to denormalize only with extreme reluctance. Then databases like mongo came along and encouraged those juniors by giving them something like a database, but where normalization was difficult/irrelevant. The result was a brief flowering of horrible database designs and unmaintainable crap towers. Now the pendulum has swing back and people have rediscovered the virtues of a normalized database, but JSON columns provide an escape hatch where those bad practices can still flower.
- christophilus 2y agoEh. JSON has its place. I have some stateful data that is fairly transient in nature and which doesn’t really matter all that much if it gets lost / corrupted. It’s the sort of thing I’d throw into Redis if we had Redis in our stack. But the only storage in my project is S3 and Postgres. Postgres allows me to trivially query, update, analyze the usage of the feature, etc. Normalization wouldn’t buy me much, if anything, for my use case, but it would make “save this stuff for later” more of a nuisance (a sync across a bunch of rows vs a single upsert). That said, I’ve worked on projects that had almost no normalization, and it was pure hell. I’m certainly not arguing against normalizing; just saying that data blobs are useful sometimes.
- codr7 2y agoYeah, I'm def not taking a any more mongodb jobs if I can avoid it. I'm fine with using it for simple throw away stuff, but deciphering someone else's ball of json is soul killing.
- yen223 2y agoThere are two reasons to use a jsonb column: 1. To store JSON. There's a pattern where when your webserver calls into some third-party API, you store the raw API response in a JSONB column, and then process the response from there. This gives you an auditable paper trail if you need to debug issues coming from that 3rd-party API. 2. To store sum types. SQL not supporting sum types is arguably the biggest deficiency when modelling data in SQL databases. There are several workarounds - one of them being "just chuck it in a JSONB column and validate it in the application" - but none of the workarounds is particularly great.
- zie 2y agoI would add: 3. End-user extra fields. Stuff you don't care about, but someone somewhere does.