Why Is My Java App Slower on EC2 but Fast Locally?

Profile Picture

KingSnu

OP
@snuchi.bsky.social
3 days ago

My Spring Boot API performs well locally but is noticeably slower after deploying to EC2.

curl -w "@curl-format.txt" -o /dev/null -s https://myapi.com/health
spring-boot postgres
Profile Picture

Gabriel Hernandez

@gabrielhs20.bsky.social
3 days ago

It might be because of different reasons. Performance differences between local and EC2 usually come down to deployment environment rather than Spring Boot itself. Some common things to check:

  • Network latency: Hitting an EC2 instance over the internet will always be slower than calling localhost.
  • Instance size: Small EC2 types (t2.micro, t3.micro) have limited CPU credits and can throttle under load.
  • Database location: If Postgres is not in the same VPC/region, every query adds network overhead.
  • Cold starts or low memory: Spring Boot apps need enough RAM and CPU to avoid GC pressure and slow startup.
  • Reverse proxy or TLS termination overhead: Nginx, ALB, or TLS can add milliseconds compared to local calls.

Compare local vs EC2 using internal VPC requests and monitor CPU, memory, and DB latency to pinpoint the bottleneck.