Java Backend Interview Q&A← All stacks

REST — Interview Q&A Matrix

Parent stack: Messaging & Integration Technology: REST Levels: Junior · Senior · Architect Questions: 3

Each entry contains a Question, the Expected Depth, an Ideal Answer, and Red Flags.

Junior

Q1 — REST fundamentals and idempotent methods

Question: What makes an API RESTful, and which HTTP methods are idempotent? Why does it matter?

Expected Depth:

Ideal Answer:

http
POST /orders HTTP/1.1
Content-Type: application/json

{"customerId":"c-42","items":[{"sku":"A1","quantity":2}]}

HTTP/1.1 201 Created
Location: /orders/o-1007
Content-Type: application/json

{"id":"o-1007","status":"PENDING"}
http
PUT /accounts/42 HTTP/1.1
If-Match: "version-7"
Content-Type: application/json

{"name":"Ada"}

Red Flags:


Senior

Q2 — Idempotency keys for REST APIs

Question: A payment POST may be retried by clients/proxies, risking double charges. Design an idempotency mechanism for the REST API.

Expected Depth:

Ideal Answer:

sql
CREATE TABLE idempotency_record (
        tenant_id       text        NOT NULL,
        operation       text        NOT NULL,
        idempotency_key text        NOT NULL,
        request_hash    text        NOT NULL,
        status          text        NOT NULL,
        response_code   integer,
        response_body   jsonb,
        expires_at      timestamptz NOT NULL,
        PRIMARY KEY (tenant_id, operation, idempotency_key)
);
java
@PostMapping("/payments")
ResponseEntity<PaymentResponse> pay(
                @RequestHeader("Idempotency-Key") String key,
                @RequestHeader("X-Tenant-Id") String tenantId,
                @Valid @RequestBody PaymentRequest request) {
        return idempotency.execute(
                        tenantId,
                        "create-payment",
                        key,
                        fingerprint(request),
                        () -> payments.charge(request, key));
}

Red Flags:


Architect

Q3 — Resilient integration: retries, timeouts, and circuit breakers

Question: A synchronous call chain across services causes cascading failures under partial outages. Design resilience patterns for inter-service communication at scale.

Expected Depth:

Ideal Answer:

java
ConnectionProvider pool = ConnectionProvider.builder("pricing")
    .maxConnections(50)
    .pendingAcquireTimeout(Duration.ofMillis(100))
    .build();

HttpClient httpClient = HttpClient.create(pool)
    .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 200)
    .responseTimeout(Duration.ofMillis(400));

WebClient pricingClient = WebClient.builder()
    .clientConnector(new ReactorClientHttpConnector(httpClient))
    .build();
java
@CircuitBreaker(name = "pricing", fallbackMethod = "cachedQuote")
@Retry(name = "pricing")
@TimeLimiter(name = "pricing")
@Bulkhead(name = "pricing")
public CompletableFuture<Quote> quote(String sku) {
    return CompletableFuture.supplyAsync(
            () -> pricingClient.quote(sku),
            pricingExecutor);
}

private CompletableFuture<Quote> cachedQuote(String sku, Throwable error) {
    return CompletableFuture.completedFuture(lastKnownGood(sku));
}
yaml
resilience4j:
    circuitbreaker:
        instances:
            pricing:
                sliding-window-size: 50
                failure-rate-threshold: 50
                slow-call-duration-threshold: 400ms
                slow-call-rate-threshold: 60
                wait-duration-in-open-state: 10s
    retry:
        instances:
            pricing:
                max-attempts: 3
                wait-duration: 100ms
    bulkhead:
        instances:
            pricing:
                max-concurrent-calls: 10
                max-wait-duration: 0
    timelimiter:
        instances:
            pricing:
                timeout-duration: 500ms

Red Flags:


Scoring Rubric

Level Pass bar
JuniorUses HTTP methods, status codes, and resource URLs correctly.
SeniorDesigns safe retries and idempotent operations under concurrency and failure.
ArchitectDefines measured resilience standards and prevents cascading failures at scale.