¿Qué campos tiene un producto? La pregunta que rompe tu esquema
Intenta diseñar la tabla productos de una tienda. Una laptop necesita RAM, procesador y pulgadas. Una bicicleta necesita talla, material y número de velocidades. Un libro necesita páginas e idioma. Ninguno de esos campos sirve para los otros dos. En clase la respuesta es conocida: normalizas, sacas una tabla atributos con pares clave-valor y vives con los JOINs. Funciona. También convierte "dame…
The core question that challenges your database design is: what fields does a product have? Different items like laptops, bicycles and books require distinct fields such as RAM, processor speed, screen size, size, material and number of gears. None of these fields are shared across all products. In class, the answer is to normalize the data, put attributes in a key-value table and join them together.
This approach works but also allows for awkward queries like listing 16 GB laptops. To explore an alternative, a catalog was built on Couchbase Capella and deployed on Render using a GitHub Actions pipeline. The result is a straightforward catalogue with no predefined schema: a product is just a JSON document with fields for type, name, category, price, creation date and a set of attributes.
The same collection is used for all products, with zero fields in common between them. The interesting part comes when querying the data. Standard SQL requires separate tables for each combination of filters, which would need to be kept synchronized whenever data is written. In contrast, Couchbase's SQL++ (formerly N1QL) allows querying using JSON documents and enables dynamic filtering based on attribute names provided at runtime.
For example, users can search for laptops with 16 GB of RAM or bicycles made of aluminum, and the query will return the relevant results without any issues. This approach also supports aggregations, such as counting the number of products in each category. Overall, this demonstrates how a flexible, attribute-based design can simplify queries and improve data management compared to a rigidly normalized schema.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.