
Java Spring Boot 3 Yrs Interview Experience
GenZ Career
Overview
This video summarizes a Java Spring Boot developer's interview experience for a role requiring three years of experience. The discussion covers various technical topics including microservices, handling duplicate orders, dependency injection, Spring bean scopes, concurrency issues with scheduled jobs, Java stream performance, thread management, immutable classes, Kafka message reliability, Spring Data JPA versus Hibernate, indexing, caching, and troubleshooting production issues under high traffic. The candidate demonstrates practical knowledge of these concepts and their application in real-world scenarios.
Save this permanently with flashcards, quizzes, and AI chat
Chapters
- Candidate Vishal Singh has three years of experience in Java, Spring Boot, and microservices.
- Previous projects include work on ICICI DG and ICICI UD, involving features like UD generation, bulk generation, verification, printing, and Excel export.
- Technologies used include RabbitMQ, Kafka, Spring Boot, and microservices.
- Current project is with the Kenya Revenue Authority.
- To prevent duplicate orders in an e-commerce scenario, a strategy is to create a table to store generated order IDs and check for existence before creating a new order.
- This approach is crucial when dealing with external service retries, like payment gateways.
- Constructor injection is a type of dependency injection where dependencies are provided through the class constructor.
- It's an alternative to field injection and promotes better testability and immutability.
- Singleton scope is the default and ensures only one instance of a bean exists per Spring application context, suitable for shared resources like database connection pools.
- Prototype scope creates a new bean instance every time it's requested, useful when each request needs a unique object.
- HTTP scope provides request-specific beans, creating a new instance for each incoming HTTP request.
- When two pods run the same scheduled job, it can lead to duplicate processing, repeated actions, or conflicting updates if not managed.
- To ensure only one pod executes a scheduled task, distributed locking mechanisms like optimistic or pessimistic locking, or leader election can be used.
- Optimistic locking involves versioning or checking for data modification before an update.
- Replacing sequential streams with parallel streams can improve performance by utilizing multiple threads, but it's not always beneficial.
- Parallel streams can sometimes slow down execution due to thread management overhead, especially with small datasets, blocking operations, or non-thread-safe code.
- The number of active threads in a project depends on factors like CPU cores, request latency, and thread pool configuration.
- A controller becoming slow after adding REST calls is often due to increased network latency or waiting for external services, not necessarily business logic changes.
- Immutable classes are classes whose state cannot be modified after creation.
- A class can remain immutable even with a list field if proper defensive copying and no setters are used.
- If a Kafka event doesn't appear after a successful payment API call, troubleshooting involves checking producer/consumer logs, topic configurations, and consumer subscriptions.
- Spring Data JPA provides a higher-level abstraction over JPA providers like Hibernate, simplifying data access.
- Spring Data JPA offers features like query derivation and integration with Spring's transaction management.
- Hibernate provides lower-level control and features like multi-level caching and session management.
- Implementing indexing in Spring Data JPA can be done by defining primary keys, foreign keys, or using annotations for specific index creation.
- Indexing is a technique to speed up data retrieval operations on database tables.
- Reducing cache TTL (Time To Live) might be necessary if users see stale data after changes, but it often masks underlying issues.
- CRUD Repository provides basic persistence operations, while JPA Repository extends it with features like pagination and sorting.
- When a JPA query becomes slow with large tables (e.g., 20 million rows), solutions include table partitioning (e.g., by date) or optimizing the Java code (e.g., using streams).
- Features working locally but failing under high production traffic often indicate concurrency issues, race conditions, or resource exhaustion.
- Troubleshooting high-traffic issues may involve increasing CPU/database connections, implementing rate limiting, analyzing thread dumps, and using distributed tracing.
- Spring singleton beans are not automatically thread-safe; shared mutable state within them can lead to race conditions if not synchronized.
- Increasing HTTP timeouts (e.g., from 5 to 30 seconds) can hide underlying performance problems rather than solving them.
- The correct approach is to investigate why requests are taking longer than expected.
- Merging code changes that only mask symptoms without addressing the root cause is not advisable.
Key takeaways
- Prevent duplicate data by implementing checks and using dedicated storage mechanisms, especially when dealing with external service retries.
- Constructor injection is preferred for dependency injection as it enhances testability and promotes immutability.
- Understand the implications of Spring bean scopes (singleton, prototype, HTTP) for resource management and object lifecycle.
- Concurrency issues in distributed systems, like duplicate scheduled jobs, require explicit locking or coordination mechanisms.
- Parallel streams can offer performance benefits but must be used judiciously, considering data size and potential overhead.
- Troubleshooting production issues under high traffic often points to concurrency problems, resource contention, or network latency.
- Always address the root cause of performance degradation or errors, rather than just masking symptoms with configuration changes like increasing timeouts.
- Spring singleton beans are not inherently thread-safe; careful design is needed if they manage shared mutable state.
Key terms
Test your understanding
- How would you design a system to prevent duplicate order creation when an external payment gateway retries a failed transaction?
- Explain the advantages of constructor injection over field injection in Spring Boot applications.
- What are the potential problems if two pods execute the same scheduled job concurrently, and how can you prevent them?
- Under what circumstances might using parallel streams in Java actually decrease performance, and why?
- If a Spring Boot application experiences issues under high traffic that don't occur in low-traffic or local environments, what are the likely root causes?
- Describe the difference between CRUDRepository and JpaRepository in Spring Data JPA and when you might choose one over the other.
- Why is simply increasing an HTTP timeout not a good solution for production errors, and what steps should be taken instead?