Storing feature flags as JSON (with indexing)

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.ย. 2024

ความคิดเห็น • 82

  • @heyjitendra
    @heyjitendra 9 หลายเดือนก่อน +21

    Honestly Aaron your videos helped me learn much more than my complete semester dbms course. Thanks Aaron and planetscale

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน +1

      😌😌 you're welcome

  • @krstnhkn
    @krstnhkn 9 หลายเดือนก่อน +4

    Holly, you have made a great decision hiring this guy! Aaron, your videos are so interesting, so helpful, every single one of them. When I was at university we had a professor for database design who took any and all interest anyone had away, by presenting databases as such a boring piece of software. I still remember you saying "I don't care about this, I just want to play with the database!" -- that showed such a great attitude, so different from those unmotivated professors back then! You're such an amazing teacher!
    And Steve... Great work there at 7:20 ! I love it, I really do!

  • @joshandromidas
    @joshandromidas 9 หลายเดือนก่อน +5

    I don't even write raw SQL in my job, but I can't stop watching these videos! Excited for the rest of this series.

  • @CWhitmer22015
    @CWhitmer22015 9 หลายเดือนก่อน +2

    I really like the way Aaron explains things. I am from the old days. Just how old you ask? In college, one of my projects was to create a system with dbase III+ for managing a VHS video rental stores operations. In those days we used a persons social secutiry number for their customer number and could not imagine why you would not do that in every system into the future.
    Amazing how things change...
    You know what hasent changed much? SQL and database concepts.
    Back to what I like so much about Aaron. He understands that there is no one right way to do things. He says it all the time. "Should you do this in the database or the applicatinn tier?!I don't know, that is for you to decide.
    I looked for the perfect way to do things for a long, long time before I realized it does not exist for most things.
    I also used to think all databased should be in 5th normal form! Or at least 4th ;-)
    Keep up the videos Aaron. I am still learning loads from them.

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน

      I really really appreciate this, you have no idea. I'm constantly trying to offer nuance on a platform that favors absolutes. Thanks for calling that out 🫶
      Funny that you did a VHS store operation, because isn't that literally the domain that the old Sakila database uses too? Too funny

  • @xcrap
    @xcrap 9 หลายเดือนก่อน +7

    Again, great content, but we're missing the most important aspect: the practicality of it. I mean, we are PHP developers; we create stuff, not just theory. So, why not have a performance comparison between three examples? These could include tables with flags using bitwise operations, flags with JSON, and just multiple tinyints, and making operations in tables with 1 million rows each to see what indexes and columns works better for real world applications ;)

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน +4

      I'll do a performance comparison as a separate video after the three in-depth ones. Good idea!

    • @kelvincjj
      @kelvincjj 8 หลายเดือนก่อน

      @@PlanetScale Any updates on this, would love to see some performance comparisons

    • @OnAirMarc
      @OnAirMarc 8 หลายเดือนก่อน

      @@kelvincjjIt might be a while. Aaron just had his second set of twins a couple weeks ago. But anything Aaron makes is well worth the wait!

  • @thisismissem
    @thisismissem 9 หลายเดือนก่อน +1

    It's kinda great you're releasing these videos atm, because I'm presently working on a proposal for trust & safety in the fediverse, and I'd initially used a bitmask, but now I'm thinking a json column may be better.

  • @RaicaBogdan
    @RaicaBogdan 9 หลายเดือนก่อน +2

    "Kinda crazy, kinda awesome ... I wouldn't do it!" haha haha😄

  • @user-co8vc5nd7l
    @user-co8vc5nd7l 9 หลายเดือนก่อน +1

    Bitmasks are unhinged but something about it is so, idk aesthetically pleasing.
    I use them everywhere I’m feeling a bit cute.
    Most recently in an powershell script that captures user variables to store during windows OS provisioning, stored in WMI and then inventoried into the ConfigMgr SQL database.
    It captures what custom features are built into the generic windows OS during build time.

  • @TheIpicon
    @TheIpicon 9 หลายเดือนก่อน +1

    I can't describe how much helpful this video was.

  • @flipperlite
    @flipperlite 8 หลายเดือนก่อน

    @PlanetScale At 12:27, it's very simple to remove array elements by value using built in functions in one line of code. Sample of JavaScript:
    // single value
    const oldValues = ['dark_mode', 'whatever']; // get from DB returning an array of strings
    const newValues = oldValues.filter(value => value != 'dark_mode');
    console.log(newValues); // ['whatever']
    OR
    // multiple values
    const oldValues = ['dark_mode', 'whatever']; // get from DB returning an array of strings
    const newValues = oldValues.filter(value => !['dark_mode', 'super_admin'].includes(value));
    console.log(newValues); // ['whatever']
    OR using functions with unique add
    function removeFlags (oldValues, ...flags) {
    return oldValues.filter(value => !flags.includes(value));
    }
    function addFlags (oldValues, ...flags) {
    return removeFlags(oldValues, ...flags).concat(flags);; // to make the output unique
    }
    const oldValues = ['dark_mode', 'whatever']; // get from DB returning an array of strings
    const newValues = addFlags(oldValues, 'whatever', 'foobar');
    console.log(newValues); // ['dark_mode', 'whatever', 'foobar']
    console.log(removeFlags(newValues, 'dark_mode', 'whatever')); // ['foobar']

  • @remkospaans
    @remkospaans 9 หลายเดือนก่อน

    Man, oh man, you can do so much with Json in MySQL... Thanks for sharing this knowledge. In my head I already see so many places where I could use this in work. Ps. Aaron's boss, give him a pat on the back! He and his team make such interesting and clear videos.

  • @LaurentBeauvisage
    @LaurentBeauvisage 9 หลายเดือนก่อน +3

    Definitely Aaron you are the best. Love all of your content.❤
    also Amazing job do by Steve in this video 😂

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน +1

      Haha steve is the funniest

  • @TravisFont
    @TravisFont 9 หลายเดือนก่อน

    Nulls are never explicit (expected) data types which usually require additional logic.
    As always, just avoid null (even in DBs).
    Sidenote, the array is technically an ArrayList. The usage of flags is a great example!

  • @itsmestevieg81
    @itsmestevieg81 9 หลายเดือนก่อน +2

    Absolutely love your videos, you definitely deserve many more followers! I always look forward to seeing what php or mysql wizardry you come up with next. Thanks again mate ✌️❤🙏

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน

      Thank you!

  • @iliesboukhatem7803
    @iliesboukhatem7803 9 หลายเดือนก่อน

    I love when you say "see you" ^_^

  • @ahmad-murery
    @ahmad-murery 9 หลายเดือนก่อน +1

    7:29 Looks like Steve is using a nullable JSON column 😃
    Thanks Aaron

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน +3

      Steve has HAD IT

  • @EricScheid
    @EricScheid 9 หลายเดือนก่อน +2

    4:12 could you also test for “!= true”?

    • @mind.journey
      @mind.journey 9 หลายเดือนก่อน +1

      I thought the same, but it only works if the key is present.
      So, {"active": null} works if you SELECT * from table where flags->'$.active' != true.
      However, if you run the same select and the column value is {} (or null), the row is not selected.

  • @abdellahcodes
    @abdellahcodes 9 หลายเดือนก่อน +1

    loving these videos, keep 'em coming ...
    I'd like to talk about your set up a bit, the lighting and background are just gorgeous
    but I couldn't help but notice a lack of sharpness on your video, maybe it's just me, I believe you could "pop" more 😁
    what camera + lens are you using?
    I'm learning video and would love to pick up some tricks from you :)
    a setup tour sometime would be awesome 😍

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน +1

      I'm running my camera at 1080p but we're rendering out at 4k, so when I'm doing the talking heads I might be a bit soft! I'm using the Canon M50 with a sigma 16mm lens. I share some behind the scenes video stuff on Twitter! twitter.com/aarondfrancis

    • @abdellahcodes
      @abdellahcodes 9 หลายเดือนก่อน

      Oh man, I'm drooling over the sigma 16 rn 😂

  • @clamhammer2463
    @clamhammer2463 9 หลายเดือนก่อน

    I love the power of json but have ALWAYS used bitmasks for feature flags. I've never really had a case where I needed to query rows based on feature flags like you are doing in the video. Just saving the mask in the table and parsing it in the application layer. To me, bitmasks make a lot more sense at scale but without seeing your other video. Maybe I'm just old.

  • @luismex5575
    @luismex5575 9 หลายเดือนก่อน

    Great content, I am looking forward to see the last part

  • @kriffos
    @kriffos 9 หลายเดือนก่อน

    I'm not sure I remember it correct, but I think Postgres can remove an item of an array by value. I prefer Postgres, but I like your videos anyways, they are really great!

  • @dogoku
    @dogoku 9 หลายเดือนก่อน

    Good Job Steve

  • @RaniLink
    @RaniLink 6 หลายเดือนก่อน

    Thank you! Your vids are always super insightful!
    Question!
    I'm building a granular permission mechanism that maps routes to actions.
    Each user would have explicit permissions to do certain actions within a given workspace.
    Would you suggest creating a JSON column for the user-workspace mapping for these actions?
    I thought about creating a user_workspace_action_mapping table but that can get big very fast:
    e.g. 1000 users, each user has 5 workspaces, each user-workspace combo has 50 actions....

  • @shravanuchil
    @shravanuchil 9 หลายเดือนก่อน +1

    You are awesome, i love your videos 😍

  • @cooldude3010
    @cooldude3010 9 หลายเดือนก่อน

    Amazing content. Please keep crushing it.

  • @VitorJustin
    @VitorJustin 9 หลายเดือนก่อน

    Great content. Thanks, Aaron!

  • @tesohh
    @tesohh 9 หลายเดือนก่อน +1

    what software are you using as a sql client? looks nice

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน

      TablePlus! th-cam.com/video/7V_CJBPZPes/w-d-xo.html

  • @JohnRoux
    @JohnRoux 9 หลายเดือนก่อน

    Amazing content as always.
    Would be suuuuuper cool to do a similar series to this, but specifically for how you'd implement these various approaches in laravel, do you cast as object or array and does eloquent nateively handle things okay or are there extra steps you'd recommend.
    In the real world, you probably don't want to be doing a sql query each time you check a feature flag :D

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน

      Good idea! This channel is primarily focused on SQL, specifically MySQL. But I'll see if there's a way we can show it anyway

  • @dimitridovgan6364
    @dimitridovgan6364 9 หลายเดือนก่อน

    Your videos are very valuable! Thank you!

  • @kakekandi
    @kakekandi 9 หลายเดือนก่อน

    great content, but how to insert a new key value to json? for example if i need a new flags in list of json

  • @joao.penteado
    @joao.penteado 9 หลายเดือนก่อน

    Awesome video as usual. What do you think about a table with user id, flag (enum or id to external table mapping to string), value (bool)?
    We can have the user_id and flag being the primary key, which also have the benefit of clustering same-user settings together physically, ensuring no conflicts and providing fast lookups.
    Additionally, we can define defaults on the application side and store only settings users explicitly set on or off (like VSCode does), saving up on storage too.
    Not sure if this is the idea for the next video, I might have misunderstood.

  • @kevinnguyen163
    @kevinnguyen163 9 หลายเดือนก่อน

    I love your content. Thank you a lot for the great work.

  • @TES-A5
    @TES-A5 9 หลายเดือนก่อน +2

    Can't we make a generated column that converts Json Column to Json array column? And create an index on that generated array column

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน +1

      Oh woah, maybe so! You'd have to be sure to query against the array... but yeah that kinda rules

    • @TES-A5
      @TES-A5 9 หลายเดือนก่อน

      @@PlanetScale that is true, query against the indexed column and insert, update, & del on the json (non-array) column... We can also make a function that converts json to json array, and use that as the index parameter for functional index

  • @jcc5018
    @jcc5018 9 หลายเดือนก่อน

    OK, I have a question. I see planetscale is a company that deals with Databases. Is it a MySQL alternative like postgre and others, or just a better user interface to do the same things? (Ie something like PHPMyAdmin) I know other options like postgre, oracle and now planet scale exists, but I dont know why I would consider switching to any of them when MySQL is what I learned on, and appears to work as of now.
    But I am also building a rather large application, so if it would be beneficial to do some future thinking, I would rather learn it now then needing to adjust things later.
    Could you consider a video that explains why one may want to consider planetScale or any other SQL based Database over others? Pros and cons of basic MySQL and so forth. Thanks

  • @SentinelaCosmica
    @SentinelaCosmica หลายเดือนก่อน

    Aaron is the best, take my money!

  • @MomovskyChannel
    @MomovskyChannel 9 หลายเดือนก่อน

    I'd ask a sort of a dumb question (maybe it will be answered in part 3 also, but I can't wait!): what's the problem with just adding these feature flags as separate columns in your table? Like, what are we losing if we have like 10 boolean columns vs just one column that stores everything either via bitmasking or JSON? Do we lose in speed of operations, in memory, in disk space? And if so, how much do we lose?
    Asking as a person who has separate columns for feature flags in tables in work project. Maybe we should think about removing those columns and moving everything in just one column/separate table?

    • @_grigoryta
      @_grigoryta 9 หลายเดือนก่อน +1

      Well, storing multiple values in one column is a 1NF violation first and foremost. So unless you don't care about basic properties of relation in relational databases then there's indeed no reason to store multiple values in one column, especially with the bit masking example as it's not only a violation but it's also very confusing to look at.
      I guess it's just about exploring the different ways of doing that.
      One other thing that might be useful with JSON storage is that you don't need to alter your database (so no migrations), you can just add new values to it. And if you map it in your code (via ORM library for example) as a Dictionary or other key-value based collection, you don't even need to alter your contract to add new values (talking about a simple 1 level JSON of course).
      Also if you have a no SELECT * policy in your code querying for JSON column always gets you the entire thing

    • @MomovskyChannel
      @MomovskyChannel 9 หลายเดือนก่อน

      @@_grigoryta thanks for the extensive answer, some good points there, I will have to look further into this.

  • @xsehrmotiviert
    @xsehrmotiviert 9 หลายเดือนก่อน

    Hey Aaron, I kinda have a problem with my selfhosted db right now. I want to use the JSON Array stuff that you showed there, but I get the following error when I want to add the flags index:
    Query 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(
    CAST(flags as char(255) array)
    ))' at line 1
    Do you know, why this keeps happening? My DB Server is MariaDB 10.11.4. The latest version is 10.11.5. I run it through Keyhelp, which is like plesk, but free to use ^^
    Looking forward to your reply

  • @dave6012
    @dave6012 9 หลายเดือนก่อน +2

    I know you’re sick of answering the IDE question, but maybe you haven’t answered this one yet: where do you get your seed data?

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน +2

      Ooo working on a video for that right now! Spoiler alert: just a Laravel command

    • @dave6012
      @dave6012 9 หลายเดือนก่อน

      @@PlanetScale you sly dog, you were psyopping me! Got my interest all piqued about the data seeding with subtle hints. I look forward to the video!

  • @MilindGokhale1
    @MilindGokhale1 8 หลายเดือนก่อน

    What is the tool you use for showing the SQL statement queries and resultset?

    • @PlanetScale
      @PlanetScale  8 หลายเดือนก่อน

      We did a video on it here! th-cam.com/video/7V_CJBPZPes/w-d-xo.html

  • @aakash2665
    @aakash2665 9 หลายเดือนก่อน

    hi, actually I have made a schema where these keys are mentioned with type
    id :uniqueid , name : string , address : json ,
    Now i want to query over the address , since it is a json array of obj [ {} , {} , .... ] .
    one object has these keys as : street , area , locality , city , pincode .
    please let me know . How can i do query over pincode I am using prisma as orm

  • @MatthewLenz
    @MatthewLenz 9 หลายเดือนก่อน

    You could have made that index unique (similar to video 3)

  • @jlsuncin
    @jlsuncin 9 หลายเดือนก่อน

    For the case of the flags as an array, would it matter if the flags are ordered or not?

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน

      Nope! Shouldn't matter at all.

  • @MarkJaquith
    @MarkJaquith 9 หลายเดือนก่อน +1

    I think I disagree with doing JSON array flag setting and removal in the application layer. Yeah, the SQL is kinda hairy... but your application layer can easily generate that hairy query! Reading data into your application, mutating it, and then updating it... is just asking for trouble.

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน

      I suppose you're right... If you wrap it all up in a scope or put it behind a builder, it'd be ok. I just was reading about how to do it and it was *gnarly*

    • @flipperlite
      @flipperlite 8 หลายเดือนก่อน

      @@PlanetScale At 12:27, it's very simple to remove array elements by value using built in functions in one line of code. Sample of JavaScript:
      // single value
      const oldValues = ['dark_mode', 'whatever']; // get from DB returning an array of strings
      const newValues = oldValues.filter(value => value != 'dark_mode');
      console.log(newValues); // ['whatever']
      OR
      // multiple values
      const oldValues = ['dark_mode', 'whatever']; // get from DB returning an array of strings
      const newValues = oldValues.filter(value => !['dark_mode', 'super_admin'].includes(value));
      console.log(newValues); // ['whatever']
      OR using functions with unique add
      function removeFlags (oldValues, ...flags) {
      return oldValues.filter(value => !flags.includes(value));
      }
      function addFlags (oldValues, ...flags) {
      return removeFlags(oldValues, ...flags).concat(flags);; // to make the output unique
      }
      const oldValues = ['dark_mode', 'whatever']; // get from DB returning an array of strings
      const newValues = addFlags(oldValues, 'whatever', 'foobar');
      console.log(newValues); // ['dark_mode', 'whatever', 'foobar']
      console.log(removeFlags(newValues, 'dark_mode', 'whatever')); // ['foobar']

  • @mityukov
    @mityukov 9 หลายเดือนก่อน

    Don't get it.. if it's not unquoted, how can we compare it with a Boolean?..

  • @jordanmckoy1935
    @jordanmckoy1935 9 หลายเดือนก่อน

    What database client is this ?

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน

      TablePlus! th-cam.com/video/7V_CJBPZPes/w-d-xo.html

  • @Farbfilmstudio
    @Farbfilmstudio 9 หลายเดือนก่อน

    How painfull is it to add a new featureflag to all users that is not false by default. Somthing like timezone or so.
    Or is this somthing you would not store in the same row as featureflag?

    • @Lexaire
      @Lexaire 9 หลายเดือนก่อน +1

      Use columns with default values, not jsonb.

    • @JohnRoux
      @JohnRoux 9 หลายเดือนก่อน +1

      Or have the default be something your app defines, and your "stored" option is just the override

  • @Vinicius7cordas
    @Vinicius7cordas 8 หลายเดือนก่อน

    Where's the third and last video?

    • @PlanetScale
      @PlanetScale  8 หลายเดือนก่อน

      Here they are: th-cam.com/video/Kf8SWqljM18/w-d-xo.html, th-cam.com/video/csLHXmVLGbs/w-d-xo.html

  • @FGj-xj7rd
    @FGj-xj7rd 9 หลายเดือนก่อน +1

    JSON in MySQL is making me older 👴🏻

  • @UwU-dx5hu
    @UwU-dx5hu 9 หลายเดือนก่อน

    I gave up planetscale after it asked for credit card info.i am a student.i dont have those.
    I only wanted to learn.

  • @balduin_b4334
    @balduin_b4334 9 หลายเดือนก่อน

    thanks for not showing me :)

  • @Lexaire
    @Lexaire 9 หลายเดือนก่อน

    These are not Feature Flags. They are just user settings.

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน

      Could be either!

  • @parazeni
    @parazeni 9 หลายเดือนก่อน

    like the thing that not good to use, and don't learn it.

  • @Dyanosis
    @Dyanosis 9 หลายเดือนก่อน

    You're not going to show us how to remove the flag from a JSON Array even though in the beginning of the video you explicitly state "remove". So I guess you lied? Typical.

    • @PlanetScale
      @PlanetScale  9 หลายเดือนก่อน +1

      I showed the json object and then said the json array should be done in the app. Do I typically lie?