Implement retry wrapper and interdependent validators

Quick Overview

This question evaluates a candidate's competence in building robust asynchronous utilities and form validation logic, covering retry/backoff strategies, error classification, per-attempt and overall timeouts, cancellation via AbortSignal, observable retry hooks, cross-field validators, state management, and accessibility considerations in JavaScript/TypeScript web applications. Category: Other / Miscellaneous; domain: web development and systems reliability in JavaScript/TypeScript; it is commonly asked because it probes both conceptual understanding of retry semantics, cancellation and validation constraints and practical implementation skills related to API ergonomics, error propagation, composable validators, and performance trade-offs.

Implement retry wrapper and interdependent validators

Company: Airbnb

Role: Software Engineer

Category: Software Engineering Fundamentals

Difficulty: hard

Interview Round: Onsite

Part A — Retry higher-order function: Implement wrapWithRetry(fn, options) for JavaScript/TypeScript functions that may throw or return a rejected Promise. Support policies: retry once, retry N times, and exponential backoff (configurable base, cap, optional jitter). Allow specifying retryable error types/conditions, per-attempt and overall timeouts, and cancellation via AbortController. Provide usage examples and discuss edge cases (synchronous throw vs asynchronous rejection, non-idempotent operations, retries outliving the caller, error propagation). Part B — Interdependent input validators: Build a component with three input fields and a validation framework where ( 1) one validator checks value length against configurable min/max, and ( 2) another validator errors when any two inputs have identical values. Changing one input must trigger revalidation of the others to keep cross-field constraints correct. Describe state management, composing per-field and cross-field validators, event triggers (onChange/onBlur), error display, accessibility, and performance considerations.

Quick Answer: This question evaluates a candidate's competence in building robust asynchronous utilities and form validation logic, covering retry/backoff strategies, error classification, per-attempt and overall timeouts, cancellation via AbortSignal, observable retry hooks, cross-field validators, state management, and accessibility considerations in JavaScript/TypeScript web applications. Category: Other / Miscellaneous; domain: web development and systems reliability in JavaScript/TypeScript; it is commonly asked because it probes both conceptual understanding of retry semantics, cancellation and validation constraints and practical implementation skills related to API ergonomics, error propagation, composable validators, and performance trade-offs.

|Home/Software Engineering Fundamentals/Airbnb
Airbnb logo
Airbnb
Sep 6, 2025, 12:00 AM
hardSoftware EngineerOnsiteSoftware Engineering Fundamentals
14
0

Context

You are implementing reusable utilities that are commonly needed in modern web apps:

  1. a robust retry wrapper for functions that can fail synchronously or asynchronously, and
  2. a small validation framework for interdependent form inputs.

The environment is JavaScript/TypeScript. You may assume access to standard Web APIs (e.g., AbortController), and you should design APIs that are ergonomic for both browser and Node runtimes.

Part A — Retry higher-order function

Implement a higher-order utility wrapWithRetry(fn, options) that wraps a JavaScript/TypeScript function which may throw synchronously or return a rejected Promise.

Requirements:

  • Retry policies:
    1. Retry once.
    2. Retry N times.
    3. Exponential backoff with configurable base/initial delay, factor, cap, and optional jitter.
  • Control which failures are retryable:
    • Allow specifying retryable error types and/or predicate functions (e.g., network errors, HTTP 5xx).
  • Timeouts:
    • Per-attempt timeout.
    • Overall timeout across all attempts.
  • Cancellation:
    • Support cancellation with AbortController / AbortSignal so the entire retrying operation can be aborted.
    • If the underlying function supports cancellation via AbortSignal , allow passing a per-attempt signal into the function.
  • Behavior and ergonomics:
    • The wrapper must handle both synchronous throws and asynchronous rejections uniformly.
    • Provide hooks to observe retries (e.g., onRetry ).
    • Return or throw the final error with meaningful context.
  • Deliverables:
    • Implementation in JS/TS.
    • Usage examples.
    • Discussion of edge cases: synchronous throw vs. asynchronous rejection, non-idempotent operations, retries outliving the caller, and error propagation.

Part B — Interdependent input validators

Build a small form component with three text inputs and a tiny validation framework.

Requirements:

  1. A per-field validator that checks value length against configurable min/max.
  2. A cross-field validator that errors when any two inputs have identical values.
  3. When any input changes, revalidate other inputs as needed to keep cross-field constraints correct.
  4. Describe and demonstrate:
    • State management for values, errors, and touched/dirty state.
    • Composing per-field and cross-field validators.
    • Event triggers (onChange, onBlur, onSubmit).
    • Error display and accessibility (e.g., aria-invalid , aria-describedby ).
    • Performance considerations (e.g., avoiding unnecessary revalidations, debouncing costly checks).

Provide a working example (TypeScript + React preferred) and explain your design choices and trade-offs.

Loading comments...