Giter VIP home page Giter VIP logo

Comments (2)

WilHall avatar WilHall commented on August 24, 2024

Hey @naps62,

This rule predates me but I can share some thoughts around the ideas behind it.

Performance (which you touched on) can certainly be an issue when querying large JSONB columns, and indexes on JSONB columns are also more expensive to generate are take up more space. Heap Analytics has a good article on the performance tradeoffs.

But the spirit of this rule is more about encouraging thoughtful data modeling. Storing data in a JSONB column results in a data model that is less well-defined and not as strongly typed. If any identifiers to other models or resources exist in that data, we lose referential integrity.

I'm much more relaxed about it. Usually I'll store anything that is either impossible or hard to retrieve again later on, because I rarely know upfront what data I'll be needing

It sounds like in some of the cases you're describing, you have a "strong reason" to store the entire response from an external source. That might be fine! In cases like that, I usually ask myself the following questions:

  1. Should my database be the source of truth for this data?
  2. Is the data really impossible to fetch again?
  3. Am I storing the data just in case I need it or is it providing value?

Not knowing what data you'll need or when/where you'll need it may indicate that you haven't fully defined the problem you're trying to solve, or haven't fully defined your data model. It could also mean you're storing data just in case, which can get expensive.

I believe this rule also makes the distinction "store an entire JSON document from an external source" to differentiate between the situation where you are storing (for example) an API response, and the situation where you know that a Customer may have many dietary restrictions and you choose to store them as a JSONB column in the form {"vegan": true, "gluten_intolerant": false} just in case you add more classifications in the future.

In the latter case, there are better ways to store that data in a relational database.

I hope these thoughts were helpful 🙂

from guides.

naps62 avatar naps62 commented on August 24, 2024

@WilHall thank you for the response. I definitely helped yes 🙏

It does sound like we're on the same page. Perhaps saying "I'm much more relaxed about it" was a bit exaggerated on my part. Most of the use cases I was thinking about fit under your rationale as well. I was mostly afraid there was some obscure drawback of using JSONB columns that I should be aware of, other than the more obvious ones.

That article does provide some great insight though. Thanks for sharing!

from guides.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.