Top 25 SQL Interview Questions for Experienced Developers

Top 25 SQL Interview Questions for Experienced Developers Work through these 15 questions out loud. Open any question for the full model answer, the trap to avoid, and the follow-up a panel usually asks.

  1. When and why use CQRS (Command Query Responsibility Segregation)?

    E-commerce: write Order aggregate to PostgreSQL; project OrderSummaryView to Elasticsearch for search/filter dashboard. Accept projection lag. Not for simple User CRUD. Combine...

    Full answer

  2. A REST API is slow only in production, not locally. How do you debug it?

    Enable Micrometer timers and Hibernate statistics or datasource-proxy in staging with prod-like data. Check Hikari `connections-active`, JVM GC pauses, and Feign/RestClient...

    Full answer

  3. 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

  4. What are text blocks and how do they improve Java code?

    String query = """ SELECT u.id, u.name FROM users u WHERE u.active = true """; — readable without \n concatenation. Use formatted for parameters carefully — prefer...

    Full answer

  5. Best practices for Spring Data pagination with Pageable?

    Controller: @PageableDefault(size=20, sort="createdAt", direction=DESC) Pageable p. Cap size at 100. Admin reports: keyset pagination on id > lastId for deep pages — OFFSET...

    Full answer

  6. What is the N+1 query problem and how do you fix it?

    Loading 100 orders then accessing each order's items triggers 101 queries. Fix with JOIN FETCH in JPQL, @EntityGraph on repository method, or a DTO query selecting only...

    Full answer

  7. 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

  8. How implement multi-tenancy in Spring Security context?

    JWT includes tenant_id — converter sets TenantContextHolder. Base entity @Column tenantId validated on save. Repository methods always include tenant predicate — or Hibernate...

    Full answer

  9. Saga pattern — choreography vs orchestration?

    Order saga: reserve inventory → charge payment → ship. Failure at payment triggers release inventory compensation. Orchestration clearer for complex flows with visibility....

    Full answer

  10. Explain the transactional outbox pattern.

    OrderService @Transactional saves Order and OutboxEvent(type=ORDER_CREATED, payload=json). OutboxProcessor @Scheduled polls FOR UPDATE SKIP LOCKED, sends to Kafka, updates...

    Full answer

  11. Database sharding strategies for high-scale Java services?

    Shard by tenant_id mod 32 — RoutingDataSource lookup. User-scoped queries single shard. Global admin reports from CQRS read replica or Elasticsearch. Plan shard key early —...

    Full answer

  12. How does @Transactional work?

    Spring creates a proxy around @Transactional beans. Calling createOrder() from another bean starts a transaction on the thread-bound EntityManager; commit on success, rollback...

    Full answer

  13. How do Spring application events work with @EventListener?

    OrderService publishes OrderCreatedEvent after save. EmailListener @EventListener sends confirmation. @TransactionalEventListener(AFTER_COMMIT) prevents email on rolled-back...

    Full answer

  14. When use @Query native SQL vs JPQL in Spring Data JPA?

    JPQL for standard entity fetches and portable logic. Native for PostgreSQL-specific jsonb queries, recursive CTEs, or performance-tuned index hints after EXPLAIN. Interface...

    Full answer

  15. How do Flyway/Liquibase integrate with Spring Boot JPA?

    Prod: spring.jpa.hibernate.ddl-auto=validate, Flyway V1__init.sql through Vn. CI: @Testcontainers PostgreSQL + Flyway migrate + integration tests. Never rename column without...

    Full answer

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

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