#1
This guide shows how to tune Apache Derby for better performance in Spring Boot web applications by using settings and coding best practices.

1. Use File-Based Storage

In application.properties:
spring.datasource.url=jdbc:derby:/app/data/webDB;create=true
spring.datasource.driver-class-name=org.apache.derby.jdbc.EmbeddedDriver
spring.jpa.hibernate.ddl-auto=update
File-based Derby performs better for production than in-memory.

2. Enable Connection Pooling

Add HikariCP settings:
spring.datasource.hikari.maximum-pool-size=20
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.idle-timeout=30000
spring.datasource.hikari.max-lifetime=1800000
This reduces connection creation overhead.

3. Batch Inserts and Updates

spring.jpa.properties.hibernate.jdbc.batch_size=50
spring.jpa.properties.hibernate.order_inserts=true
spring.jpa.properties.hibernate.order_updates=true
Batching reduces round-trips to Derby.

4. Index Frequently Queried Columns

Example migration script:
CREATE INDEX idx_customer_email ON customer(email);
Indexes improve query performance on search-heavy fields.

5. Use Streaming for Large Reads

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.stream.Streamable;

public interface CustomerRepository extends JpaRepository<Customer, Long> {
    @Query("SELECT c FROM Customer c")
    Streamable<Customer> streamAll();
}
Streaming avoids memory overload on large datasets.

6. Limit Logging in Production

spring.jpa.show-sql=false
logging.level.org.hibernate.SQL=ERROR
Excessive logging slows down apps handling high loads.

7. Monitor Performance

Add Actuator for metrics:
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Check connection pool and query timings via /actuator/metrics.

image quote pre code