Best practices

Review these best practices to decide how to use Products and Product Variants to model your data.

  • After completing this page, you should be able to:

    • Explain the best practices associated with product data modeling.
    • Demonstrate how to use these best practices in a simple scenario.
  • Let’s revisit the diagram of the product data model:

    A diagram showing the relationships between product types, products, product variants and categories.

    In general, we recommend creating more Products with fewer Product Variants. As we mentioned previously, Products contain Product Variants, which contain Product Attributes. From a data standpoint, this means the size of a large Product can reach the JSON document size limit. In particular, creating Products that have too many Product Variants can cause issues with performance.

    When modeling products, be mindful of the amount of data that a single Product contains. It’s important to be strategic about what you choose to model as a Product Variant and what the purpose of a Product Attribute is.

    We suggest you approach modeling your products with the following workflow:

    1. Analyze your current product set’s attributes. Pay attention to which attributes are common to all (or a group of) products, and which are not common.
    2. Decide on your major product groups, and what their common attributes are. These will become your Product Types.
    3. Decide on the granularity of a Product and a Product Variant. In general, more Products with fewer Product Variants is recommended.
    4. Try different options: don’t commit to a product model before seeing if it will work in some typical but also less common scenarios! Especially focus on your worst-case scenarios (Products with lots of Product Variants) and test the performance.
  • Also, keep in mind the following when modeling products:

    • Product URL slugs, display names, and search keywords are modeled on Products, not Product Variants. Keep this in mind when optimizing your product modeling for Search Engine Optimization (SEO) purposes.
    • Product names are weighted 6x more heavily than other Product Attributes in full-text searches. When naming Products, select a name carefully that doesn't use terms that only apply to one Product Variant.
    • Tax Categories are modeled on the Product level: when deciding on which variables to model as Product Variants, keep in mind that all Product Variants must share the same Tax Category.

    Modeling practice

    Let’s put these best practices to work by examining how to model products for a bookstore.

    Analyze the Product Attributes

    The main identifier for books is the International Standard Book Number (ISBN). All books have the following properties:

    • ISBN-10
    • ISBN-13
    • Title
    • Author
    • Publisher
    • Publishing date
    • Description

    ISBNs are issued per book, and each edition or publishing format will have its own ISBN.

    Decide on Product Types

    Our bookstore only sells one thing: books. No accessories, no book bags, no bookmarks, or notebooks. Therefore, we can safely model one product type: book, with the attributes previously listed.

    Before doing so, we need to ask some questions:

    • What data types should the attributes be? While it’s tempting to store everything, especially things like ISBNs as strings, this can lead to bad data later. Similarly, we could store authors and publishers as a single string, but this could lead to issues where books with multiple authors are listed incorrectly.
    • Should we localize? One of the strengths of Composable Commerce is its robust out-of-the-box support for the localization of product data. However, storing localized fields when you don’t need them can lead to large amounts of unnecessary data.
    • Which fields should be required? It’s helpful to think of the final product detail page you’re trying to construct when deciding on required fields. At a minimum, how much information does that page need? Are there any other field constraints?

    After thinking things through, we arrive at the following:

  • Product Type: Book

    Attributes:

    • ISBN-10: number (required)
    • ISBN-13: number (required)
    • Title: localized string (required)
    • Author: set of localized strings (required)
    • Publisher: set of localized strings (optional)
    • Publishing date: date (optional)
    • Description: localized string (optional)
  • Choose how to display your Products

    Now that you have decided on your Product Type, some decisions remain to be made about how you wish to display books on your web pages. Remember, there is no one best way to do this. What is important is that you think about your end goal (what your product pages will look like) and that you work within the Composable Commerce product data model.

    Let's practice this in the following quiz questions.

    Test your knowledge