Skip to content

Donggeun10/support

Repository files navigation

Backend Server Features

  • RESTful API Server Sample code based on Spring boot
  • Major Exceptions are managed by RestControllerAdvice and ExceptionHandler
  • Database such as H2DB is accessed such as insert, select, update and delete (CRUD) via Spring Data JPA
  • It controls race condition using LockModeType.PESSIMISTIC_WRITE provided JPA
  • API Documentation using Springdoc-openapi
  • Code simplification using Lombok
  • Container creation and execution using Docker
  • Logging using Aspect and @Around
  • Add security configuration using Spring Security such as basic authentication
  • Add link to response using HATEOAS
  • Add Server-Sent Event (SSE) example for real-time notification

1. Frameworks And Tools

  • JDK 21
  • spring-boot 3.3.5
  • spring-boot-web
  • spring-boot-data-jpa
  • spring-boot-security
  • spring-boot-cache
  • ehcache / hazelcast
  • springdoc-openapi
  • h2database
  • lombok
  • spring-boot-hateoas

2. Api Spec URL

3. Endpoints

  • GET /api/v1/announcements
  • GET /api/v1/announcements/page
  • GET /api/v1/announcement/id/{id}
  • POST /api/v1/announcement
  • POST /api/v1/announcement/id/{id}
  • PUT /api/v1/announcement/id/{id}
  • DELETE /api/v1/announcement/id/{id}
  • DELETE /api/v1/announcement/id/{id}/file-id/{fileId}

4. Docker container creation and execution command

docker build -t demo-api:local .  && docker run -p 9090:8080  -e"SPRING_PROFILES_ACTIVE=local"  demo-api:local
docker build -t demo-api:local -f Dockerfile_git . && docker run -p 9090:8080  -e"SPRING_PROFILES_ACTIVE=local"  demo-api:local
docker build -t demo-api:local -f Dockerfile_aot . && docker run -p 9090:8080  -e"SPRING_PROFILES_ACTIVE=local"  demo-api:local
docker build -t demo-api:local -f Dockerfile_cds . && docker run -p 9090:8080  -e"SPRING_PROFILES_ACTIVE=local"  demo-api:local
docker-compose up

5. Definition of key problems and solution strategies

  • Race condition problem of database access
    • Apply to restrict access to other sessions during change through lock such as LockModeType.PESSIMISTIC_WRITE (for update) in DB table row
  • Lack of memory problem by increasing platform threads
    • In order to reduce memory usage per request, using virutal thread
    • Parallel processing through jdk.virtualThreadScheduler.parallelism setting, default value is number of cpu core
  • Security Problem
    • Apply universal security configuration to handle spring security
    • Only authenticated users can access the API through basic authentication or OAuth Token
  • Problem of frequently access database for authentication in short time
    • Apply local cache through Ehcache
    • Apply cache data sharing through Hazelcast clustering
  • Instance startup time and library loading issues
    • Minimize instance startup time through image creation through Graalvm AOT compilation

6. Test account and method

  • account
    • robot / play
    • sam / ground
  • method
    • swagger-ui.html

7. Effective cache engines adaption via ehcache or hazelcast

  • Ehcache can be compiled to native image by GraalVM in order for local caching and executed properly
  • It is hard to compile Hazelcast native image via GraalVM, and Hazelcast might not be supported officially
  • SpringBoot cache with Hazelcast 5.2.4 is compiled by GraalVM native image and executed properly, however, another Hazelcast versions such as over 5.2.4 can be compiled but occurred runtime error.
  • When application is started, Hazelcast needs to get cluster information and make a clustering. so it has needed to time to complete Clustering and synchronizing cache data.

8. Native image size and startup time

About

Java / SpringBoot 3 기반 웹서버 샘플코드

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published