Cardinality
Cardinality is the size of a set, collection, value domain, or relationship, commonly expressed as the number of its distinct members or values.
Grokking Relational Database Design
Cardinality is the number of instances of a target entity that can be associated with one instance of a source entity in a directional relationship.
- How it is used
- Guides E-R diagram design by turning relationship requirements into cardinalities and foreign-key decisions.
- How deep it goes
- Explains directional minimum and maximum limits, notation, three relationship types, and implementation consequences including insertion constraints.
- Examples
- Uses user-account, department-manager, and user-review relationships to derive cardinalities and table links.
- What you can do after
- Apply it to classify entity relationships, draw Crow’s Foot limits, and place foreign keys or junction tables.
Read how Grokking Relational Database Design explains cardinality →
Graph Algorithms for Data Science
Query cardinality is the number of rows or records in the input or intermediate result stream available to a query operation.
- How it is used
- Guides Cypher aggregation and sequential pattern matching so counts remain meaningful and queries avoid unnecessary work.
- How deep it goes
- Defines row-stream cardinality and demonstrates distinct counts, counting subqueries, and intermediate reduction with Cypher queries.
- Examples
- Uses Twitter mentions, independent User and Tweet matches, and mention-distribution queries to expose repeated and multiplied rows.
- What you can do after
- Diagnose/debug with Cypher by identifying row multiplication, selecting distinct counts, and reducing intermediate streams with aggregation.
Read how Graph Algorithms for Data Science explains cardinality →
Latency
Cardinality is the number of distinct values in a dataset or column.
- How it is used
- Uses cardinality to guide partition-key selection for horizontally partitioned data.
- How deep it goes
- Defines high and low cardinality and explains their implications for partition balance, with workload-skew caveats.
- Examples
- Contrasts distinct user IDs with a limited set of order statuses.
- What you can do after
- Evaluate partition keys for potential imbalance while accounting for hot partitions and skewed writes.
Logs and Telemetry
Cardinality is the number of distinct label-value combinations or dimensions represented in a telemetry data set.
- How it is used
- Guides Prometheus label design and telemetry sizing for querying, diagnosis, correlation, and exporter operation.
- How deep it goes
- Defines dimensions and demonstrates their output, while warning about operational effects without exploring cardinality management in depth.
- Examples
- Uses CPU, disk, server, exporter, service-group, and greeting labels to contrast dimensioned metrics with aggregate totals.
- What you can do after
- Evaluate metric labels by comparing diagnostic value with the additional values collected and calculated for each dimension.
Ensemble Methods for Machine Learning
Cardinality is the number of unique categories or values represented by a categorical feature.
- How it is used
- Guides categorical encoding decisions by distinguishing features with few categories from high-cardinality string features.
- How deep it goes
- Defines unique-category counting and connects it to encoding tradeoffs, but stops short of formal analysis.
- Examples
- Uses employee job titles, category-count diagnostics, spelling variants, and alternate titles as concrete examples.
- What you can do after
- Apply it via category-count diagnostics and choose encoders such as SimilarityEncoder, MinHashEncoder, or GapEncoder.
Read how Ensemble Methods for Machine Learning explains cardinality →
PostgreSQL Mistakes and How to Avoid Them
Cardinality is the number or diversity of distinct values in a set or key column.
- How it is used
- Guides selection of partition keys that distribute PostgreSQL rows evenly across partitions.
- How deep it goes
- Explains distribution consequences and stops short of a general mathematical treatment.
- Examples
- Uses monthly timestamp partitions and contrasts full-table scanning with a plan scanning one partition.
- What you can do after
- Evaluate partition keys for even distribution and anticipate excessive scans or poor execution plans.
Read how PostgreSQL Mistakes and How to Avoid Them explains cardinality →
Outlier Detection in Python
The number of distinct values or categories represented by a variable or column.
- How it is used
- Uses cardinality to distinguish categorical from string columns and to calibrate categorical outlier detection.
- How deep it goes
- Explains cardinality through column types, count distributions, normalized rarity, and sparse combinations, but does not develop a formal estimator.
- Examples
- Uses staff expenses, SpeedDating categorical distributions, and multi-column combination counts to illustrate cardinality.
- What you can do after
- Evaluate whether categorical rarity or multi-column sparsity supports an outlier flag without treating uncommon values as automatically anomalous.
Cloud Observability in Action
Metric cardinality is the number of distinct values or combinations represented by a metric’s dimensions or labels.
- How it is used
- Frames metric-label design as a practical driver of observability storage and query costs.
- How deep it goes
- Defines cardinality and demonstrates its cost implications, while deferring detailed cardinality-explosion treatment.
- Examples
- Contrasts HTTP status-code labels with user-ID labels in metric series.
- What you can do after
- Evaluate metric labels for potential storage and query-cost increases.
Read how Cloud Observability in Action explains cardinality →
Also covered in
- Secure APIs
- Build Python Web Apps with Streamlit
- MongoDB 8.0 in Action, Third Edition
- Quarkus in Action
- Machine Learning for Tabular Data: XGBoost, Deep Learning, and AI
- Machine Learning Algorithms in Depth
What to know first
- regular expressionA regular expression is a formal pattern notation for describing sets of strings and matching, searching, or transforming text according to those patterns.
Related concepts
- data aggregationconfigured by · Data aggregation is the process of combining multiple data values, records, or observations into a consolidated or summarized result.
- edgepart of · An edge is a connection between two vertices or nodes in a graph or related structure, representing a relationship and optionally carrying direction, labels, or weights.
- countconfigured by · A count is a numerical operation or value associated with the number of elements, occurrences, rows, or units in a specified collection or domain.
Questions about cardinality
What is cardinality?
Cardinality is the size of a set, collection, value domain, or relationship, commonly expressed as the number of its distinct members or values.
Which Manning books explain cardinality?
Grokking Relational Database Design, Graph Algorithms for Data Science, Latency, Logs and Telemetry, Ensemble Methods for Machine Learning, PostgreSQL Mistakes and How to Avoid Them, Outlier Detection in Python and Cloud Observability in Action.
What should I know before learning cardinality?
Manning books that teach cardinality usually introduce regular expression first.
What is the difference between cardinality and counting subquery?
Cardinality is the size of a set, collection, value domain, or relationship, commonly expressed as the number of its distinct members or values. A counting subquery is a nested query that counts matching graph patterns while preserving the row cardinality of its enclosing query.
What kinds of cardinality are there?
Kinds of cardinality include prime elliptic curve cardinality.
What is cardinality part of?
Cardinality is part of edge. An edge is a connection between two vertices or nodes in a graph or related structure, representing a relationship and optionally carrying direction, labels, or weights.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.







