What database & design would you use for legos

database-designdesign-patterndimensional-modelingnosqlrelations

I'm trying to conceptualize an interesting problem I am designing for. Using lego's (the plastic construction toys) as an analogy seems to work well. If this is a fairly recognizable problem, then I'd appreciate any reference to related information.

Given the scenario details below, what database would you choose, i.e. RDB/SQL or NoSQL or Graph or lucene or ?, and how might you considering modeling the design. Given:

  1. "lego materials" or simply all of the individual type of lego pieces that may exist.

    • Each individual piece has metadata / various characteristics such as size, color, bottom/top knobs & gaps, constraints, etc.
  2. "builders catalog" of all of the possible number of building blocks/modules you could create using multiple pieces.

    • metadata here might include descriptions, the manufacturers of the module, all of the pieces used to create the module, intended purpose, what knobs/gaps are able to be built on etc.
  3. "final creations"

    • essentially all the various lego sets sold as products. The data will include generic terms describing the build, like "castle", "city", "airplane", etc. Then, the instructions which detail every module required to be built to build the final creation.

The solution needs to address scale and the ability to search across all of our objects and their relations to each other. I feel graph dbs may not be able to scale to this intended purpose. Further, the data will grow with every addition to the objects above.

Questions we'd query:

(lego materials) show me all the pieces I have… or… Find a piece structured like this one (using meta data) but also
all the places it has been used to build a module in our builders catalog
(below), as well as final creations… or… find me all the pieces I can place on top of this piece

(builders catalog) Similar composability type questions above as it relates to modules connecting to one another, and final creations. Also… find other modules using the similar lego pieces as this one

(final creations) What other creations are a part of this set (like a Batman series)… or what other creations use similar modules, or similar pieces as this creation.

Best Answer

A standard RDBMS could easily handle this problem. You have a defined schema, a simple one at that, which deals with common industry problems such as Inventory and Production.

Having worked at an engineering and manufacturing company, all of our systems (even third party that we utilized) were on RDBMS, generally Microsoft SQL Server. But any RDBMS would work just fine, such as PostgreSQL, Oracle, or MySQL, to name a few of the mainstream options. So this is a real-world standard use case.

One tip I'll mention is besides our raw Items table (which had a unique row for every part number that we sell or consume at some level of an assembly) we had a table that stored a row for every direct Parent-Child relationship between all of our part numbers. This is immensely useful for querying for any and all possible combinations of things we build at any level of any final assembly item we sell (or sub-assembly / module that goes into that final assembly). You can easily utilize such a table in a recursive self-join (in most RDBMS this is doable via a recursive CTE) to get the entire hierarchy of a parts list for anything then, in your case any Module or FinalCreation. This table had a Quantity column also, to signify how many units of the specific Child part goes into the Parent.

An example of this table would be, if you had a FinalCreation called ABCD, and it was made up of Module B and C and a single raw LEGO brick called D. And let's pretend Module B is made up of raw LEGO brick Z and three D bricks also. Your Parent-Child table, with the columns (ParentItem, ChildItem, Quantity) would have a row for (ABCD, B, 1), (ABCD, C, 1), and (ABCD, D, 1). It would also have a row for (B, Z, 1) and (B, D, 3). With your Parent-Child table you can recursively build the hierarchy of these rows by self-joining on the ParentItem and ChildItem columns to each other. You can even get metrics by grouping and summing on the Quantity column, which in this case would tell you that the FinalCreation ABCD requires a total of 4 raw bricks of item D in inventory.

Finally, I'd just like to point out that despite a RDBMS being a good fit for the problem you're trying to solve, mostly any type of database system will handle scaling (in terms of amount of data vs performance) just the same (just to clarify for future readers). Scaling is a hardware and architecture problem, not a database system problem. Some database systems can support different types of scaling in different ways which may or may not be conducive to one's needs, but it's never a question of which one handles performance better.