NoteTube

Java Spring Boot 3 Yrs Interview Experience
31:20

Java Spring Boot 3 Yrs Interview Experience

GenZ Career

9 chapters8 takeaways18 key terms7 questions

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.

How was this?

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.
Understanding a candidate's background and project experience helps set the context for the technical questions that follow, highlighting areas of practical application.
Worked on ICICI DG and ICICI UD projects, handling UD generation and export to Excel.
  • 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.
This section addresses common real-world problems like data duplication and explores fundamental design patterns like dependency injection, which are critical for building robust applications.
Using a dedicated table to store order IDs to prevent duplicates during retries from external payment services.
  • 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.
Understanding bean scopes is fundamental to managing object lifecycles and resource usage in Spring applications, while concurrency issues with scheduled jobs highlight the need for careful distributed system design.
Using singleton scope for a database connection pool object to allow reuse across multiple threads.
  • 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.
This chapter delves into strategies for managing concurrent operations and optimizing performance, emphasizing that performance improvements are context-dependent and require careful analysis.
Using `SELECT ... FOR UPDATE` (pessimistic locking) or version checks (optimistic locking) to ensure only one process modifies a record at a time.
  • 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.
This section explores the complexities of thread management and identifies common performance bottlenecks, while also reinforcing the principles of designing robust, immutable objects.
A class with a list field remains immutable if the list is copied defensively in the constructor and getter, and no method allows modification of the internal list.
  • 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.
This covers critical aspects of asynchronous communication with Kafka and contrasts two popular data access technologies, highlighting how to ensure data integrity and leverage framework features.
Checking Kafka producer and consumer logs to diagnose why a payment success event was not processed.
  • 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.
This section focuses on optimizing database performance through indexing and caching strategies, and clarifies the differences between Spring Data JPA repository types.
Using pagination and sorting methods provided by JPA Repository to efficiently retrieve and display large datasets.
  • 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.
This chapter addresses critical production troubleshooting scenarios, emphasizing the importance of identifying root causes for performance degradation under load and understanding the nuances of thread safety in Spring.
Partitioning a large table by date to improve query performance on historical data.
  • 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.
This final point reinforces the principle of addressing the root cause of issues rather than just mitigating symptoms, a crucial aspect of effective software development and maintenance.
Investigating why a service request now takes 30 seconds instead of 5, rather than simply increasing the HTTP timeout.

Key takeaways

  1. 1Prevent duplicate data by implementing checks and using dedicated storage mechanisms, especially when dealing with external service retries.
  2. 2Constructor injection is preferred for dependency injection as it enhances testability and promotes immutability.
  3. 3Understand the implications of Spring bean scopes (singleton, prototype, HTTP) for resource management and object lifecycle.
  4. 4Concurrency issues in distributed systems, like duplicate scheduled jobs, require explicit locking or coordination mechanisms.
  5. 5Parallel streams can offer performance benefits but must be used judiciously, considering data size and potential overhead.
  6. 6Troubleshooting production issues under high traffic often points to concurrency problems, resource contention, or network latency.
  7. 7Always address the root cause of performance degradation or errors, rather than just masking symptoms with configuration changes like increasing timeouts.
  8. 8Spring singleton beans are not inherently thread-safe; careful design is needed if they manage shared mutable state.

Key terms

Spring BootMicroservicesDependency InjectionConstructor InjectionSpring Bean ScopesSingleton ScopePrototype ScopeKafkaSpring Data JPAHibernateIndexingCachingConcurrencyParallel StreamsThread SafetyRate LimitingDistributed TracingDefensive Copying

Test your understanding

  1. 1How would you design a system to prevent duplicate order creation when an external payment gateway retries a failed transaction?
  2. 2Explain the advantages of constructor injection over field injection in Spring Boot applications.
  3. 3What are the potential problems if two pods execute the same scheduled job concurrently, and how can you prevent them?
  4. 4Under what circumstances might using parallel streams in Java actually decrease performance, and why?
  5. 5If 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?
  6. 6Describe the difference between CRUDRepository and JpaRepository in Spring Data JPA and when you might choose one over the other.
  7. 7Why is simply increasing an HTTP timeout not a good solution for production errors, and what steps should be taken instead?

Turn any lecture into study material

Paste a YouTube URL, PDF, or article. Get flashcards, quizzes, summaries, and AI chat — in seconds.

No credit card required