Week at Work · System Design Case Study

Designing a Rules-Driven Employee Break Scheduling System

How a simple break generation and placement feature evolved into a configurable scheduling rules engine capable of generating and validating employee breaks while respecting dynamic legal windows.

Rules Engine Scheduling Algorithms Domain Modeling CQRS Workforce Management
Product
Week at Work
My Role
System Architect & Developer
Primary Challenge
Dynamic break-rule enforcement
Architecture
Rules + Validation
01 — OVERVIEW

Scheduling breaks is not the same as counting breaks.

Break requirements can depend on shift duration, uninterrupted work time, employee attributes, employer policies, and whether one type of break can satisfy another requirement.

For Week at Work, the break scheduling system was designed around a core separation: what the rules require should remain independent from how the schedule chooses to satisfy those requirements.

The resulting architecture can determine required breaks, calculate ideal placement, validate manually adjusted schedules, and prepare valid schedules for optimization across an entire day's workforce.

Separate the legal or policy obligation from the scheduling decision used to satisfy it.

02 — THE PROBLEM

Straightforward scheduling rules break down quickly.

A reliable break system has to understand both the breaks themselves and the periods of uninterrupted work created between them.

1

Variable Rules

Break requirements may depend on shift length, consecutive work, employee scope, or employer policy.

2

Multiple Requirements

Longer shifts may require multiple meals or recurring rest-break obligations.

3

Break Substitution

A meal may satisfy a rest requirement in some circumstances without universally eliminating the rest.

4

Manual Changes

Managers may move scheduled breaks after generation, potentially invalidating the original schedule.

5

Dynamic Windows

Legal placement windows can shift after qualifying breaks interrupt consecutive periods of work.

6

Operational Coverage

Individually valid break schedules can still create poor staffing coverage if too many employees break simultaneously.

03 — SCHEDULING PIPELINE

Break requirements and break placement are separate stages.

The algorithm first determines the obligations generated by the rules, then progressively converts those obligations into scheduled breaks.

Rules Configured policies
Applicable Rules Employee + shift scope
Required Breaks Obligations
Ideal Timing Preferred placement
Placement Legal schedule
Validation Work segments

Each stage answers a different question, reducing the complexity that would result from trying to generate persisted ShiftBreak records directly from raw rules.

04 — RULE MODEL

Model the rule instead of hard-coding a specific policy.

The engine supports different trigger models so labor requirements can evolve independently of the scheduling algorithm.

Shift-Length Trigger

Requirements based on the total duration of an employee's scheduled shift.

ShiftLengthEqualsOrExceeds(6 hours)
→ require meal
6 hours → Meal #1
10 hours → Meal #2

Consecutive-Work Trigger

Requirements based on the amount of uninterrupted work performed since a qualifying break.

ConsecutiveMinutesWorked(240)
→ require rest
qualifying break
→ reset work segment

Consecutive-work rules behave fundamentally differently because the work timeline changes whenever a qualifying break occurs.

05 — INTERMEDIATE MODELS

Don't schedule directly into persistence entities.

Intermediate models allow each stage of the scheduling algorithm to represent exactly the information it needs.

Break Rule Configured policy
RequiredBreak Rule obligation
IdealBreak Window + preference
Placed Break Selected time
ShiftBreak Persisted schedule

A required break can carry details such as break type, duration, paid status, trigger offsets, legal-window constraints, substitution behavior, and whether the underlying rule operates as a rolling window.

Scheduling-only concepts remain in the scheduling domain instead of becoming unnecessary persistent database state.

06 — IDEAL PLACEMENT

Give the scheduler a legal window and a preferred position.

Rather than committing immediately to a start time, the system first calculates a legal range and an ideal target inside that range.

If the preferred time is unavailable, the placement algorithm can search nearby candidates—such as five minutes earlier or later—while remaining inside the allowable window.

07 — BREAK SUBSTITUTION

Meal suppression is really requirement satisfaction.

A meal overlapping a rest window does not automatically mean the rest can safely disappear.

A naive implementation might remove a rest whenever a meal occurs inside the same window. That can create another excessively long period of uninterrupted work later in the shift.

The more useful abstraction is to treat rest rules as obligations requiring a work period to be interrupted by a qualifying break.

Suppression is not fundamentally about deleting a break. It is about determining whether another break satisfies the obligation created by the rule.

08 — WORK-SEGMENT VALIDATION

Validate the timeline, not the number of breaks.

The validator reconstructs the shift as alternating periods of work and qualifying breaks, then evaluates each resulting work segment.

10:00 AM 9:00 PM
Work
Meal
Work
Rest
Work
3h 30m 10:00–1:30
2h 20m 2:00–4:20
4h 25m 4:35–9:00 · Violation

An employee can have the correct number of meals and rest breaks while still violating a consecutive-work rule.

09 — DYNAMIC LEGAL WINDOWS

Break timing follows the actual work timeline.

Static windows anchored only to shift start become insufficient once qualifying breaks can reset the consecutive-work clock.

Work Starts
Consecutive Work Boundary
Qualifying Break
New Work Segment

Dynamic windows provide one shared concept that can support scheduling, validation, optimization, and UI explanations.

10 — HUMAN OVERRIDES

Generated schedules must coexist with manager decisions.

Managers need the ability to move breaks for operational reasons without the scheduling engine silently destroying intentional changes.

Generated Breaks

Breaks initially created by the rules engine.

Existing Breaks

Previously scheduled breaks that participate in future validation and recalculation.

Manually Adjusted

Manager-selected break positions that should be preserved whenever possible.

Completed Breaks

Historical schedule state that cannot simply be regenerated away.

Human scheduling decisions and automated compliance validation should complement each other rather than compete for ownership of the schedule.

11 — SERVICE ARCHITECTURE

Scheduling, validation, and optimization solve different problems.

BreakScheduler

Determines which breaks an employee requires and where those breaks should initially be placed.

BreakValidator

Determines whether the resulting schedule continues to satisfy all applicable rules.

Break Rules
BreakScheduler
BreakValidator
Valid Schedule
12 — CQRS INTEGRATION

Keep CQRS handlers focused on orchestration.

The scheduling algorithms live in application services instead of being embedded directly inside commands and query handlers.

Command / Query
CQRS Handler
BreakScheduler
BreakValidator
Repository

This makes the scheduler and validator independently testable while allowing the same services to participate in schedule creation, shift editing, previews, and automated optimization workflows.

13 — DESIGN PRINCIPLES

Architectural lessons that shaped the final system.

Model the Rule

Represent triggers, scope, duration, recurrence, and substitution behavior as data instead of hard-coded scheduling logic.

Separate Generation and Validation

A generated schedule may be valid initially but must still be independently validated after later changes.

Validate Work Segments

Compliance depends on when breaks occur, not merely how many breaks appear on the schedule.

Use Intermediate Models

RequiredBreak, IdealBreak, LegalWindow, and WorkSegment each represent a distinct scheduling concern.

Respect Human Decisions

Existing and manually adjusted breaks should participate in future validation rather than simply being regenerated.

14 — OUTCOME

A small rules engine for practical workforce scheduling.

The final architecture separates legal requirements, scheduling decisions, validation, and operational optimization so each concern can evolve independently.

Configurable Policies Supports employer-specific and employee-specific break rules.
Multiple Trigger Models Shift-length and consecutive-work requirements can coexist.
Dynamic Legal Windows Break timing adapts to the actual work timeline.
Work-Segment Validation Detects violations that simple break counts cannot.
Manual Adjustments Human scheduling decisions remain compatible with automated compliance checking.
The most important architectural decision was separating what is required, where it should be scheduled, and whether it remains valid.

Explore More of My Work

See additional system design, software architecture, and product development projects.