Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. #RubyOnRails database and app design question in the vicinity of inventory management:

#RubyOnRails database and app design question in the vicinity of inventory management:

Scheduled Pinned Locked Moved Uncategorized
rubyonrails
19 Posts 4 Posters 0 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • jgarber@social.lolJ jgarber@social.lol

    @sstephenson There’s a related model I didn’t mention, RestockingLevel, whose most useful attribute is minimum allowable quantity for a particular SKU at a particular Warehouse.

    It’s closely related to what I outlined in the problem statement, but isn’t exactly the same. Its utility is more in triggering action when certain conditions are met.

    So maybe “StockLevel” for this new join model…? 🤔

    sstephenson@indieweb.socialS This user is from outside of this forum
    sstephenson@indieweb.socialS This user is from outside of this forum
    sstephenson@indieweb.social
    wrote last edited by
    #10

    @jgarber yeah, I like that, nice parity

    jgarber@social.lolJ 1 Reply Last reply
    0
    • sstephenson@indieweb.socialS sstephenson@indieweb.social

      @jgarber yeah, I like that, nice parity

      jgarber@social.lolJ This user is from outside of this forum
      jgarber@social.lolJ This user is from outside of this forum
      jgarber@social.lol
      wrote last edited by
      #11

      @sstephenson It was right in front of me the whole time!

      Appreciate your feedback on this one.

      I’m responsible for an app that’s growing beyond its initial and rudimentary data model. I’m beginning to see a path out of the current problems, but it’ll involve some tricky data migrations in addition to the foundational modeling improvements.

      1 Reply Last reply
      0
      • jgarber@social.lolJ jgarber@social.lol

        @davetron5000

        “should SKU belong to a warehouse?”

        I don’t believe so, no. SKU here would be for categorization and reporting, as you noted.

        davetron5000@ruby.socialD This user is from outside of this forum
        davetron5000@ruby.socialD This user is from outside of this forum
        davetron5000@ruby.social
        wrote last edited by
        #12

        @jgarber stitch fix had this exact model and we counted items per SKU when needed. The primary DB did not have reporting data cached on it. So a count of items in a SKU per warehouse was not modeled in Rails explicitly.

        Transactional logic in our case never needed to know the counts. Only reporting and that was not needed realtime.

        Much of our complex transactional queries were in SQL-way easier to understand and maintain than Active Record.

        jgarber@social.lolJ 1 Reply Last reply
        0
        • davetron5000@ruby.socialD davetron5000@ruby.social

          @jgarber stitch fix had this exact model and we counted items per SKU when needed. The primary DB did not have reporting data cached on it. So a count of items in a SKU per warehouse was not modeled in Rails explicitly.

          Transactional logic in our case never needed to know the counts. Only reporting and that was not needed realtime.

          Much of our complex transactional queries were in SQL-way easier to understand and maintain than Active Record.

          jgarber@social.lolJ This user is from outside of this forum
          jgarber@social.lolJ This user is from outside of this forum
          jgarber@social.lol
          wrote last edited by
          #13

          @davetron5000 The app I'm working on operates at a fraction of a fraction of a percent of the scale of StitchFix. 😅

          Strictly internal app for managing serialized inventory between various locations out there in the real world and making sure we restock depending on configured conditions, contractual obligations, etc.

          So, in this case at least, the reporting aspect (knowing how much inventory is where and when) is part of the core function.

          There's also a bunch of knock-on data-related tasks that the team's pulling out from a replica database and using some off-the-shelf dashboard kind of thing. I tend not to have much to do with that, though.

          davetron5000@ruby.socialD 1 Reply Last reply
          0
          • jgarber@social.lolJ jgarber@social.lol

            @davetron5000 The app I'm working on operates at a fraction of a fraction of a percent of the scale of StitchFix. 😅

            Strictly internal app for managing serialized inventory between various locations out there in the real world and making sure we restock depending on configured conditions, contractual obligations, etc.

            So, in this case at least, the reporting aspect (knowing how much inventory is where and when) is part of the core function.

            There's also a bunch of knock-on data-related tasks that the team's pulling out from a replica database and using some off-the-shelf dashboard kind of thing. I tend not to have much to do with that, though.

            davetron5000@ruby.socialD This user is from outside of this forum
            davetron5000@ruby.socialD This user is from outside of this forum
            davetron5000@ruby.social
            wrote last edited by
            #14

            @jgarber Yeah, the last place I worked was at a tiny scale, but I still put non-normalized data into separate tables. Maybe more infra than you want, but I had migrations for reporting tables + models in the rails app, and then regular tasks to query the normalized data and populate the reporting stuff. Even in that case, the reporting was needed at most daily, so again realtime was not a factor.

            I just balk at the rails "auto update some count" thing because how could you ever trust it?

            jgarber@social.lolJ 1 Reply Last reply
            0
            • davetron5000@ruby.socialD davetron5000@ruby.social

              @jgarber Yeah, the last place I worked was at a tiny scale, but I still put non-normalized data into separate tables. Maybe more infra than you want, but I had migrations for reporting tables + models in the rails app, and then regular tasks to query the normalized data and populate the reporting stuff. Even in that case, the reporting was needed at most daily, so again realtime was not a factor.

              I just balk at the rails "auto update some count" thing because how could you ever trust it?

              jgarber@social.lolJ This user is from outside of this forum
              jgarber@social.lolJ This user is from outside of this forum
              jgarber@social.lol
              wrote last edited by
              #15

              @davetron5000 You know, that’s a good call out that’s got me thinking: How “real time” does my app’s statistical data (inventory counts at locations, etc.) really need to be?

              Rhetorical in this conversation, but something for me to consider with the folks at work tomorrow.

              On your last point: I actually don’t mind counter caches! I haven’t (yet) gotten bitten by one on an association but that could be a consequence of the small scale I’m operating at. Or, I’ve missed some problems. 😂

              davetron5000@ruby.socialD 1 Reply Last reply
              0
              • jgarber@social.lolJ jgarber@social.lol

                @davetron5000 You know, that’s a good call out that’s got me thinking: How “real time” does my app’s statistical data (inventory counts at locations, etc.) really need to be?

                Rhetorical in this conversation, but something for me to consider with the folks at work tomorrow.

                On your last point: I actually don’t mind counter caches! I haven’t (yet) gotten bitten by one on an association but that could be a consequence of the small scale I’m operating at. Or, I’ve missed some problems. 😂

                davetron5000@ruby.socialD This user is from outside of this forum
                davetron5000@ruby.socialD This user is from outside of this forum
                davetron5000@ruby.social
                wrote last edited by
                #16

                @jgarber just takes one update in db console and your counts are off 🙂

                1 Reply Last reply
                0
                • jgarber@social.lolJ jgarber@social.lol

                  #RubyOnRails database and app design question in the vicinity of inventory management:

                  • Your app has a Warehouse model,
                  • a serialized InventoryItem model, and
                  • a SKU model

                  An InventoryItem belongs to a SKU and belongs to a Warehouse. Over time, InventoryItems move between Warehouses but the association to a SKU is static.

                  Out there in the real world, you're managing inventory at multiple locations •and• need to know precisely which InventoryItems (based on serial numbers) are in which Warehouses.

                  How would you design an efficient means of tracking not only which InventoryItems are in which Warehouse (fairly easy with associations) but also tracking the •count• of each SKU at each Warehouse?

                  So, something a bit more complicated (as far as I can think about it, at least) than a typical `belongs_to` and `counter_cache` setup.

                  pointlessone@status.pointless.oneP This user is from outside of this forum
                  pointlessone@status.pointless.oneP This user is from outside of this forum
                  pointlessone@status.pointless.one
                  wrote last edited by
                  #17

                  @jgarber I feel like I’m missing something. SKU is a type of thing, InventoryItem is a thing, and Warehouse is a place.

                  So to count thing you do select count(id) from inventory_items group by warehouse, sku.

                  Or did I read that completely wrong?

                  jgarber@social.lolJ 1 Reply Last reply
                  1
                  0
                  • R relay@relay.mycrowd.ca shared this topic
                  • pointlessone@status.pointless.oneP pointlessone@status.pointless.one

                    @jgarber I feel like I’m missing something. SKU is a type of thing, InventoryItem is a thing, and Warehouse is a place.

                    So to count thing you do select count(id) from inventory_items group by warehouse, sku.

                    Or did I read that completely wrong?

                    jgarber@social.lolJ This user is from outside of this forum
                    jgarber@social.lolJ This user is from outside of this forum
                    jgarber@social.lol
                    wrote last edited by
                    #18

                    @pointlessone Nope, I don't think you're missing anything!

                    pointlessone@status.pointless.oneP 1 Reply Last reply
                    0
                    • jgarber@social.lolJ jgarber@social.lol

                      @pointlessone Nope, I don't think you're missing anything!

                      pointlessone@status.pointless.oneP This user is from outside of this forum
                      pointlessone@status.pointless.oneP This user is from outside of this forum
                      pointlessone@status.pointless.one
                      wrote last edited by
                      #19

                      @jgarber if that’s too slow see if you can add some indices, if still slow wrap Rails.cache around it.

                      1 Reply Last reply
                      1
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups