KatInterview

Backend Design for Employee Records and Payroll Audit System

System DesignModel answer
HardModel answerSystem Designdatabasesconcurrencyapi-design

Last updated

Build a backend architecture for managing employee data and payroll changes with strong audit trails, concurrency safety, and regional customization support.

Problem Description

You're building the backend for a workforce management platform. The system tracks employee information, processes salary modifications, and handles time-off approvals. Your architecture must guarantee data integrity, complete audit trails, and flexibility for region-specific requirements.

Design solutions for three interconnected challenges:

1. Data Architecture

Create a database schema supporting Employee and SalaryModification entities. Your design must preserve every historical change—when someone's compensation changes, you need both old and new values, timestamps, and who made the change. Consider: how do you accurately compute paychecks when salary changes mid-period?

2. Concurrent Operations

Two managers might simultaneously approve the same leave request. Your system must prevent duplicate processing—the employee shouldn't lose double the vacation days, and only one approval notification should send. What mechanisms ensure exactly-once semantics?

3. Regional Flexibility

Different locations require different data. California needs state disability insurance codes, while Texas doesn't. European offices track works council membership. How do you support arbitrary location-specific attributes without constant schema changes?

Requirements

  • Define REST API endpoints for salary updates
  • Explain your auditability strategy (tracking who, what, when for every modification)
  • Target system: 100,000 employees with high write traffic during monthly payroll cycles
  • Pro-rating example: If salary increases from $96,000 to $120,000 halfway through a pay period, the paycheck must reflect the blended rate accurately

What to Deliver

Provide database schemas, API specifications, concurrency control mechanisms, and extensibility patterns. Explain trade-offs between different approaches and justify your choices with concrete reasoning.

Hints

Hint 1

Think about whether you should update existing records or create new ones when data changes—which approach better supports audit requirements?

Hint 2

Consider what database primitives prevent two transactions from making conflicting changes to the same resource

Hint 3

Evaluate structured vs semi-structured storage for optional fields: what does each approach cost you in query performance and flexibility?