Developer Knowledge Hub

Technical Guides & Architecture

Authoritative references on Indian holiday regulations, HRMS leave automation patterns, and multi-state compliance integration.

Architecture & Integration8 min readUpdated Sep 2026

Automating HRMS Leave Calendars & Payroll Calculations Across 37 States

Engineering guide on architecting automated holiday syncing, shift scheduling, sandwich leave rule handling, and multi-state compliance using the Calendar API.

1. The Multi-State Payroll Challenge

Modern Indian tech companies and distributed enterprises employ workforces distributed across multiple states and union territories. Hardcoding static holiday arrays in application databases causes continuous compliance drift when state governments announce ad-hoc holidays, election closures, or shifting lunar calendar dates (e.g. Eid, Diwali, Holi). A modern Human Resource Management System (HRMS) needs a decoupled holiday resolution pipeline that queries authoritative holiday APIs on-demand or during scheduled payroll runs.

2. Solving the Sandwich Leave Problem

Many Indian enterprise HR policies enforce the **Sandwich Rule**: If an employee takes leaves immediately preceding and succeeding a public holiday or weekend, the intervening holiday days are also deducted from their leave balance. To compute this accurately: 1. Determine the employee's work location state code (`region`). 2. Query `GET /v1/holidays/range?country=IN&start={start_date}&end={end_date}&region={state}`. 3. Check if all surrounding workdays are marked as unpaid/leave. 4. Calculate net deductible days without manual HR intervention.

3. Caching & Performance Architecture

Since public holiday lists for a calendar year are largely deterministic with rare executive updates: - Fetch and cache the annual regional payload (`GET /v1/calendar?country=IN&year=2026&region=TN`) in Redis with a 24-hour TTL. - For transactional date validation (e.g. attendance punch reconciliation), hit `GET /v1/date/is-holiday?country=IN&date=YYYY-MM-DD&region=DL` with sub-10ms cache latency. - Invalidate cache entries automatically when the API's `updated_at` timestamp advances.

4. Node.js Middleware Implementation

Code Reference
// Express.js middleware for HRMS holiday gating
import fetch from 'node-fetch';

export async function isWorkday(req, res, next) {
  const { date, employeeState } = req.body;
  const url = `https://calendar-api-d7a8.onrender.com/v1/date/is-holiday?country=IN&date=${date}&region=${employeeState}`;
  
  try {
    const response = await fetch(url);
    const result = await response.json();
    
    if (result.is_holiday) {
      req.isWorkingDay = false;
      req.holidayDetails = result.holiday;
    } else {
      req.isWorkingDay = true;
    }
    next();
  } catch (err) {
    req.isWorkingDay = true; // Fallback to normal day on network timeout
    next();
  }
}
Topics:#hrms leave calendar automation#payroll cutoff calculation#sandwich leave rule logic#multi-state workforce attendance#leave management system api
Test in API Playground