Spring Boot Interview Questions and Answers – Part 7: Redis, Scheduling, Async Processing, Spring Batch & Logging

Introduction :

Welcome to Part 7 of the Spring Boot Interview Questions and Answers series!

In the previous part, we explored modern microservices concepts, including OpenFeign, WebClient, Kafka, RabbitMQ, Docker, Kubernetes, API Versioning, and Cloud Deployment.



In this article, we'll focus on advanced Spring Boot features that are commonly used in enterprise applications to improve performance, scalability, reliability, and maintainability. These topics are frequently asked in Java Full Stack Developer, Spring Boot Developer, and Microservices interviews.

Let's dive in!


91. What is Redis and why is it used in Spring Boot?

Answer:

Redis (Remote Dictionary Server) is an in-memory data store used for:

  • Caching
  • Session Management
  • Rate Limiting
  • Real-time Analytics
  • Message Broker

Because Redis stores data in memory, it is much faster than querying a database repeatedly.

Advantages

  • Extremely fast
  • Reduces database load
  • Improves application performance
  • Supports distributed caching

92. How do you enable caching in Spring Boot?

Answer

Steps:

  1. Add Redis dependency
  2. Configure Redis
  3. Enable caching
@SpringBootApplication
@EnableCaching
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

}

Example:

@Cacheable("employees")
public Employee getEmployee(Long id) {
return repository.findById(id).orElse(null);
}

93. What are @Cacheable, @CachePut and @CacheEvict?

@Cacheable

Stores method results in cache.

@Cacheable("products")

@CachePut

Updates the cache whenever the method executes.

@CachePut("products")

@CacheEvict

Removes data from cache.

@CacheEvict(value="products", allEntries=true)

94. What is Spring Scheduling?

Answer

Spring Scheduling executes tasks automatically at predefined intervals.

Enable scheduling:

@EnableScheduling

Example:

@Scheduled(cron = "0 0 12 * * ?")
public void generateReport() {
System.out.println("Generating Report...");
}

95. Difference between fixedRate, fixedDelay and cron?

FeatureDescription
fixedRate        Runs after a fixed interval
fixedDelay        Runs after previous execution completes
cron        Runs based on cron expression

96. What is Asynchronous Processing?

Answer

Async processing allows long-running tasks to execute in separate threads without blocking the main request.

Enable:

@EnableAsync

Example:

@Async
public void sendEmail() {
// Email Logic
}

Benefits

  • Better performance
  • Faster API response
  • Parallel execution

97. What is Spring Batch?

Answer

Spring Batch is used for processing large amounts of data.

Typical use cases:

  • Payroll
  • Bank Transactions
  • Insurance Claims
  • Data Migration
  • Report Generation

Core Components

  • Job
  • Step
  • ItemReader
  • ItemProcessor
  • ItemWriter

98. What is SLF4J?

Answer

SLF4J (Simple Logging Facade for Java) is the standard logging API used in Spring Boot.

Example:

private static final Logger logger =
LoggerFactory.getLogger(EmployeeService.class);

logger.info("Employee created");
logger.error("Database error");

99. Which logging framework does Spring Boot use?

Answer

Spring Boot uses:

Logback

Features

  • Fast
  • Flexible
  • Easy configuration
  • Supports rolling log files

100. How do you configure logging levels?

Example:

logging.level.root=INFO
logging.level.com.example=DEBUG

Levels

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR

101. What is Spring Boot Actuator?

Answer

Spring Boot Actuator provides production-ready monitoring endpoints.

Common Endpoints

  • /health
  • /metrics
  • /beans
  • /env
  • /info

Benefits

  • Health Monitoring
  • Metrics
  • Application Status
  • Production Diagnostics

102. What is Micrometer?

Answer

Micrometer is Spring Boot's metrics collection library.

It integrates with:

  • Prometheus
  • Grafana
  • Datadog
  • New Relic

103. How do you improve Spring Boot application performance?

Answer

Best practices:

  • Use caching
  • Optimize database queries
  • Use pagination
  • Enable compression
  • Use connection pooling
  • Async processing
  • Lazy loading
  • Monitor with Actuator
  • Optimize JVM settings

104. What is Global Exception Handling?

Answer

Spring Boot provides centralized exception handling using:

@RestControllerAdvice

Example:

@RestControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(Exception.class)
public ResponseEntity<String> handle(Exception ex) {
return ResponseEntity
.badRequest()
.body(ex.getMessage());
}

}

Benefits

  • Cleaner code
  • Consistent API responses
  • Better error handling

105. What is the difference between @ControllerAdvice and @RestControllerAdvice?

@ControllerAdvice            @RestControllerAdvice
Used with MVC Views        Used with REST APIs
Returns View/Page         Returns JSON Response

106. What are production deployment best practices?

Answer

A production-ready Spring Boot application should include:

  • Externalized configuration
  • Environment-specific profiles
  • Centralized logging
  • Health checks
  • Monitoring
  • HTTPS
  • Docker containers
  • Kubernetes deployment
  • Secure secrets management
  • Database backups
  • CI/CD pipelines

107. What is Blue-Green Deployment?

Answer

Blue-Green Deployment is a deployment strategy where:

  • Blue = Current Production
  • Green = New Version

Traffic switches to Green only after successful testing, minimizing downtime and making rollback easier.


108. What is Rolling Deployment?

Answer

Rolling Deployment updates application instances gradually instead of replacing all instances at once.

Benefits:

  • Zero downtime
  • Reduced deployment risk
  • Easier rollback
  • Continuous availability

Interview Tips

Interviewers often ask scenario-based questions such as:

  • Why would you choose Redis over a database query?
  • When should you use @Async?
  • How would you schedule a nightly batch job?
  • How do you monitor a Spring Boot application in production?
  • What deployment strategy would you recommend for a banking application?
  • How do you implement centralized exception handling?
  • How do you optimize a slow Spring Boot application?

Prepare answers with real-world examples from your projects whenever possible.


Conclusion :

In Part 7, we explored advanced Spring Boot concepts that help build high-performance, scalable, and production-ready enterprise applications. We covered Redis caching, Spring Scheduling, Asynchronous Processing, Spring Batch, Logging with SLF4J and Logback, Spring Boot Actuator, Micrometer, Performance Optimization, Global Exception Handling, and deployment strategies such as Blue-Green and Rolling Deployments.

📚 Spring Boot Interview Series

Continue your Spring Boot interview preparation with the previous parts of this series:

Happy Learning! 🚀

Comments

Popular posts from this blog

React Basics – How to Create Component

How to Build REST API using Spring Boot (Step-by-Step Guide)

Spring Boot @RequestParam Annotation Explained with Real-Time Examples