# Stratified Sampling

Stratified sampling divides a population into defined, nonoverlapping groups and randomly selects records from each group to create a sample.

Cloud concept. Updated 2026-10-29. Page: https://blowstack.com/tools/cloud-concepts-hub/stratified-sampling

> The groups, called strata, are defined using attributes such as region, customer tier, source system, or transaction type. Sampling within each stratum helps engineers evaluate data quality across important segments instead of allowing large groups to dominate the results.

Practice exams covering Stratified Sampling: [DEA-C01 AWS Certified Data Engineer - Associate](https://blowstack.com/practice-exams/aws-certified-data-engineer-associate).

## 6 key aspects of Stratified Sampling

Stratified sampling combines deliberate group coverage with random selection, appropriate allocation, and weighted interpretation of population-level results.

1. **Explicit population and strata**: Define the dataset, time window, and grouping attributes before selecting records. Include a defined treatment for null or unknown grouping values so no records are unintentionally excluded.
2. **Random selection within groups**: Select records randomly within each stratum rather than choosing convenient files or the earliest rows. This supports valid probability-based estimates and reduces selection bias.
3. **Flexible sample allocation**: Proportional allocation preserves population shares, while disproportionate allocation gives selected groups more coverage. Choose allocations based on required precision, group size, inspection cost, and operational importance.
4. **Weighted population estimates**: When sampling fractions differ across strata, account for those differences when calculating overall quality metrics. Keep population counts and inclusion probabilities with the sample so downstream reports can apply the correct weights.
5. **Segment-level quality visibility**: Evaluate quality separately for each stratum to identify localized ingestion or transformation failures. A healthy overall metric can otherwise conceal a serious problem in a small source system.
6. **Sampling uncertainty and execution cost**: Larger samples generally improve precision but increase processing and inspection work. Exact per-group selection may require costly distributed sorting, and sampled checks can still miss rare defects.

## Cloud services for Stratified Sampling

A typical workflow uses Athena to inspect stratum sizes in a data lake, then AWS Glue or Amazon EMR to generate samples and run data quality checks at scale. Sample outputs should retain grouping attributes, population counts, and selection metadata. Amazon Redshift can combine those results with warehouse data to report both per-stratum findings and weighted population estimates. These services provide execution engines rather than an automatic guarantee of representative sampling: engineers must define the population, choose allocations, implement random selection, and verify that reported metrics account for unequal sampling fractions.

- **[AWS Glue](https://blowstack.com/tools/cloud-services-hub/aws-glue)**: AWS Glue Spark ETL jobs can implement stratified sampling using Spark DataFrame operations such as sampleBy or per-group window functions. Fraction-based sampleBy selection produces variable group counts rather than guaranteed exact quotas.
- **[Amazon Athena](https://blowstack.com/tools/cloud-services-hub/amazon-athena)**: Amazon Athena can count strata and select samples from data in Amazon S3 using SQL window functions and random ordering within each group. Sampling queries can still scan substantial data, so a smaller output does not necessarily mean a proportionally smaller query bill.
- **[Amazon EMR](https://blowstack.com/tools/cloud-services-hub/amazon-emr)**: Amazon EMR can run Spark jobs that sample large datasets by stratum and calculate weighted quality metrics. Engineers can choose approximate fraction-based selection or implement exact per-group allocations according to workload requirements.
- **[Amazon Redshift](https://blowstack.com/tools/cloud-services-hub/amazon-redshift)**: Amazon Redshift can implement stratified selection with SQL window functions partitioned by the stratum columns and ordered by RANDOM(). Store population counts and sample allocations alongside results to support weighted warehouse reporting.

## Stratified Sampling exam questions

Real practice exam questions on Stratified Sampling, with the correct answer and its explanation.

### Question 1 (DEA-C01)

**Question:**

An AWS Glue Spark job creates daily samples of application logs for data quality checks. Logs are grouped by deployment region, and smaller regions require higher sampling rates. The target rates are 1% of records from one region, 5% from another, and 20% from a third. Approximate sample sizes are acceptable.

Currently, the job randomly selects the same percentage of S3 objects within each region and then randomly selects 100 records from each selected object. Objects contain between 1,000 and 100,000 records. Engineers discover that records in smaller objects are more likely to appear in the samples.

Which change will achieve the target regional sampling rates while giving every record within a region the same probability of selection?

**Correct answer:** Assign each record an independent uniform random value between 0 and 1. Retain records whose values are below the sampling threshold configured for their region.

**Explanation:** This applies random selection within each regional stratum using its assigned sampling rate. Each record in a region has the same inclusion probability regardless of object size, and the expected regional sample sizes match the targets. The resulting overall sample deliberately gives smaller regions greater coverage.

## Practice Stratified Sampling in a full exam

Questions on Stratified Sampling in each practice exam, with every answer option and an explanation for each:

- [DEA-C01](https://blowstack.com/practice-exams/aws-certified-data-engineer-associate): 3 questions

## What is Stratified Sampling

Stratified sampling is a probability sampling technique that separates a population into mutually exclusive, collectively exhaustive groups called strata, then randomly selects records within every stratum. Each record must belong to exactly one stratum. Useful strata reflect differences relevant to the investigation, such as source system, geographic region, device type, or ingestion date. For data quality assessment, this approach helps expose problems that a simple random sample might miss in small but operationally important groups.

Consider a pipeline that processes one million transactions daily: 900,000 from one source system, 90,000 from another, and 10,000 from a third. A proportional sample of 1,000 records would allocate 900, 90, and 10 records respectively. This preserves the population's source-system distribution, but ten records may provide insufficient evidence about the smallest source. An engineer could instead select 300 records from each source to support more useful source-level comparisons.

That second design uses disproportionate allocation. It improves coverage of smaller groups, but its raw combined error rate does not represent the overall population error rate. To estimate the population rate, weight each stratum's observed error rate by that stratum's share of the population. Equivalently, for simple random sampling without replacement within each stratum, each sampled record has a population expansion weight of N\_h divided by n\_h, where N\_h is the stratum population size and n\_h is its sample size.

In a cloud pipeline, first define the population and time window, count records by stratum, and choose sample allocations. Use distributed processing or SQL to perform random selection within each group, then apply checks for missing values, invalid formats, inconsistent business rules, and other quality issues. Store the sampled records together with their stratum, population count, sampling probability, and run identifier. Keeping these details makes results interpretable and supports repeatable investigations.

A SQL implementation can assign ROW\_NUMBER() over each stratum ordered by a random expression, then retain rows up to the required allocation. This can require expensive scans, shuffles, and sorts. Fraction-based sampling may be cheaper, but often produces approximate rather than exact group sizes. A seeded random generator can support reproducibility under controlled execution conditions; a stable hash of a unique record identifier can support repeatable selection when its distribution is suitable.

Stratified sampling is not cluster sampling: stratification samples within every group, whereas cluster sampling selects groups and examines records within the selected groups. It is also not simply taking the first records from each partition, which can introduce ordering bias. Storage partitions can help identify strata, but partitioning alone does not perform sampling. Excessively detailed strata create many tiny groups and increase operational complexity.

For certification scenarios, choose stratified sampling when important subpopulations need deliberate representation. It can improve precision when the strata explain variation in the measured quality characteristic, but it does not guarantee that rare defects will be detected. Sample-based validation estimates quality; it does not prove that every record satisfies a constraint. Use full-data checks where requirements demand exhaustive validation, such as enforcing uniqueness or rejecting every malformed record.

## Learn Stratified Sampling in lessons

2 short lessons on Stratified Sampling in 1 certification course.

- DEA-C01: Random Sampling and Stratified Sampling: subgroup coverage (Premium), https://app.blowstack.com/lessons/random-sampling-and-stratified-sampling-subgroup-coverage-dea-c01
- DEA-C01: Stratified Sampling: designing samples across data segments (Premium), https://app.blowstack.com/lessons/stratified-sampling-designing-samples-across-data-segments-dea-c01
