Handling Concurrent API Calls in Spring Boot

Handling Concurrent API Calls in Spring Boot

When building Spring Boot applications, handling concurrent API calls efficiently is crucial to ensure optimal performance and scalability. Here are a few approaches to manage concurrent read and write operations: Handling Concurrent Read API Calls Asynchronous Methods Using @Async at @Service annotation and enabling asynchronous processing can help handle multiple API calls concurrently. @Async public CompletableFuture<String> asyncMethod() { // Call external API return CompletableFuture.completedFuture("Result"); } WebClient with Reactor Spring WebFlux’s WebClient allows for reactive programming, making it easier to handle multiple API calls. ...

February 20, 2025 · 2 min · Özkan Pakdil
load balancing client side

What is load balancing and how to do it on client side

“Load balancing” can be explained as maintaining any workload. For example if you have to serve 1000 breakfast in the morning you can divide the work among 2-3 or more caterers to lower the delivery/preparation time. In the computer world, same logic applies, if you want to deliver fast, you can divide the work, for example for a website we can have 5-10 webserver, this way website will be delivered faster(especially during high traffic), this is server side. ...

January 9, 2025 · 2 min · Özkan Pakdil

JTE new template engine in spring boot starter site

Last week I saw that there is new template engine in spring boot starter site Then I remembered that I have spring template engine comparison benchmark here and I wonder how is JTE performance compared to thymeleaf or freemarker. below is the latest numbers from java 23 build Engine Name Seconds jsp 6.652 velocity 3.728 freemarker 2.616 thymeleaf 6.932 mustache 3.100 jade 3.503 pebble 3.519 handlebars 13.405 scalate 3.987 httl 3.430 chunk 4.430 htmlFlow 1.670 trimou 2.059 rocker 1.957 ickenham 4.342 rythm 3.411 groovy 751.200 kotlinx 2.422 jte 2.940 JTE(2.9) is still slower then freemarker(2.6), it is still faster then jsp and mustache and thymeleaf. Also here you can see older test results. ...

October 13, 2024 · 1 min · Özkan Pakdil

Printing running sqls in logs with spring boot 3 and hibernate 6

In application.properties logging.level.org.hibernate=info logging.level.org.hibernate.SQL=debug logging.level.org.hibernate.orm.jdbc.bind=trace logging.level.org.hibernate.stat=debug logging.level.org.hibernate.SQL_SLOW=info logging.level.org.hibernate.cache=debug will make print all sqls and bindings with it like below 2023-04-08T09:31:54.232+01:00 DEBUG 164224 --- [ main] org.hibernate.SQL : insert into "address" ("city", "line1", "post_code", "id") values (?, ?, ?, ?) 2023-04-08T09:31:54.232+01:00 TRACE 164224 --- [ main] org.hibernate.orm.jdbc.bind : binding parameter [1] as [VARCHAR] - [Glasgow] 2023-04-08T09:31:54.232+01:00 TRACE 164224 --- [ main] org.hibernate.orm.jdbc.bind : binding parameter [2] as [VARCHAR] - [apt:0] 2023-04-08T09:31:54.232+01:00 TRACE 164224 --- [ main] org.hibernate.orm.jdbc.bind : binding parameter [3] as [VARCHAR] - [G0] 2023-04-08T09:31:54.232+01:00 TRACE 164224 --- [ main] org.hibernate.orm.jdbc.bind : binding parameter [4] as [BIGINT] - [28]

April 8, 2023 · 1 min · Özkan Pakdil

Printing running sqls with P6spy in spring boot 3 and hibernate 6

in build.gradle implementation 'p6spy:p6spy:3.9.1' In application.properties spring.datasource.url=jdbc:p6spy:h2:mem:testdb spring.datasource.driverClassName=com.p6spy.engine.spy.P6SpyDriver and in spy.properties driverlist=org.h2.Driver appender=com.p6spy.engine.spy.appender.StdoutLogger logMessageFormat=com.p6spy.engine.spy.appender.CustomLineFormat customLogMessageFormat=%(currentTime)|%(executionTime)|%(sqlSingleLine) With this configuration application logs will appear in console. like below 2023-04-08T12:14:54.237+01:00 DEBUG 178209 --- [nio-8080-exec-4] o.s.w.f.CommonsRequestLoggingFilter : Before request [GET /byname/name1] 1680952494240|0|select c1_0."id",c1_0."last_name",c1_0."name" from "customer" c1_0 where c1_0."name"='name1' 1680952494242|0|select a1_0."customer_id",a1_1."id",a1_1."city",a1_1."line1",a1_1."post_code" from "customer_addresses" a1_0 join "address" a1_1 on a1_1."id"=a1_0."addresses_id" where a1_0."customer_id"=2 1680952494244|0|select o1_0."customer_id",o1_1."id",o1_1."create_time",o1_1."full_price",o1_1."items",o1_1."update_time",o1_1."version" from "customer_orders" o1_0 join "order" o1_1 on o1_1."id"=o1_0."orders_id" where o1_0."customer_id"=2 1680952494246|0|select b1_0."customer_id",b1_1."id",b1_1."create_time",b1_1."items",b1_1."update_time",b1_1."version" from "customer_baskets" b1_0 join "basket" b1_1 on b1_1."id"=b1_0."baskets_id" where b1_0."customer_id"=2 If required user can change the log format like described here, here is working example project. P6spy is good for development but should not be used in production, for production every database has their own monitoring logging solution which will show what sql is running from which user. ...

April 8, 2023 · 1 min · Özkan Pakdil