Top 20 Caching Interview Questions and Answers

Top 20 Caching Interview Questions and Answers Work through these 20 questions out loud. Open any question for the full model answer, the trap to avoid, and the follow-up a panel usually asks.

  1. Your Spring Boot app works locally but fails after deployment. What are the first 3 things you check?

    First: confirm `spring.profiles.active` and required env vars exist in prod (`kubectl describe pod`, deployment manifest). Second: read startup logs and `/actuator/health` —...

    Full answer

  2. Your application memory usage keeps increasing over time. What do you suspect?

    Suspect memory leak if heap used grows after GC without traffic drop. Capture heap dump on OOM (`-XX:+HeapDumpOnOutOfMemoryError`), compare dominator tree. Common in Spring:...

    Full answer

  3. You deployed a new version but users still hit the old behavior. Why?

    Check K8s rollout status — old ReplicaSet still receiving traffic. Bust cache on static assets; API GET with `Cache-Control`. Confirm image tag in running pod matches CI build....

    Full answer

  4. How do you implement rate limiting for APIs?

    Apply at API Gateway; in-app use Redis-backed limiter for cluster-wide counts. ```java @RateLimiter(name = "apiLimiter") @GetMapping("/users") public List<User> users() {...

    Full answer

  5. API returns correct data but response time is inconsistent. Why?

    Tail latency often from stop-the-world GC, connection pool contention, or cold cache. Monitor p99 separately from mean. ```yaml spring.datasource.hikari.maximum-pool-size: 10...

    Full answer

  6. You enabled caching but performance did not improve. Why?

    Measure hits/misses. Wrong key expression caches per wrong granularity. ```java @Cacheable(value = "users", key = "#id") public User findById(Long id) { return...

    Full answer

  7. Autoscaling enabled but error rate increases. Why?

    New pods accept traffic before JVM/Caffeine warm. HPA adds API pods but Postgres max connections fixed. ```yaml readinessProbe: initialDelaySeconds: 30 ``` Scale connection...

    Full answer

  8. What are sequenced collections in JDK 21, and which calls replace fragile index access?

    I reach for getFirst/getLast on lists and deques instead of magic indexes. For a recent-activity map I use LinkedHashMap as a SequencedMap and pollFirstEntry to evict oldest....

    Full answer

  9. What is Anthropic prompt caching in LangChain4j 1.22.0, and when is it worth turning on?

    I put the interviewer persona, tool JSON, and the static policy appendix in the cached system prefix. The user question and this-request RAG chunks stay dynamic. If the prefix...

    Full answer

  10. Explain CAP theorem in the context of microservices.

    When a network split isolates nodes, you cannot have both perfect consistency and every node answering. Example: order service during partition — either reject writes (CP) or...

    Full answer

  11. What is circuit breaker pattern?

    When payment service errors exceed 50% in 10s window, breaker opens — return fallback immediately for 30s. Half-open lets one request through to test recovery. Pair with...

    Full answer

  12. Explain microservices vs monolith trade-offs.

    Start monolith until team or scale pain justifies split. Microservices enable independent deploy and tech diversity but add network failures, observability burden, and data...

    Full answer

  13. What is the difference between ArrayList and LinkedList?

    ArrayList: dynamic array, great for get(i) and iteration, amortized append. LinkedList: node chain, costly random access, only wins for frequent insert/remove in middle with...

    Full answer

  14. How would you design a rate-limited REST API?

    API gateway or filter applies token bucket per API key — Redis stores tokens with TTL. Exceeding limit returns 429 + Retry-After. Different tiers per plan. Log rejections for...

    Full answer

  15. What is an ExecutorService and why use it?

    Instead of new Thread per task, submit Runnable to fixed pool sized to CPU/IO profile. Handle Future results and exceptions. On shutdown hook call shutdown() and...

    Full answer

  16. What are weak references and WeakHashMap use cases?

    Attach metadata to objects without extending their lifetime — canonical mapping while object lives. When key GCs, entry drops. Do not rely on timing. For API response caching...

    Full answer

  17. What is Spring Boot Docker Compose dev services support?

    Add compose.yaml with postgres and redis services. Include spring-boot-docker-compose on runtimeOnly. Boot starts Postgres, sets JDBC URL — zero local install. CI uses...

    Full answer

  18. What is Hibernate second-level cache and when enable it?

    Enable for ProductCategory, Currency — READ_ONLY, rarely changed. spring.jpa.properties.hibernate.cache.use_second_level_cache=true with Caffeine region factory. Avoid on...

    Full answer

  19. What are idempotency keys and how implement them in REST APIs?

    Client sends Idempotency-Key: uuid on POST /payments. Server Redis SETNX key, process, store response JSON. Retry with same key returns 201 + original body without double...

    Full answer

  20. Redis caching patterns: cache-aside vs write-through?

    @Cacheable("users") on findById — Redis cache-aside via Spring Data Redis. Update user: @CacheEvict. TTL 15m + jitter. Hot product page: lock on miss with Redisson. Do not...

    Full answer

Caching Interview Questions and Answers · Top 50 Caching Interview Questions and Answers (2026 Edition) · Top 40 Caching Interview Questions | Must-Prepare before interview. · Caching Interview Questions Every Fresher Must Know

All interview question lists · Interview guides · Home · Support the platform