Introduction
Describes how to develop RESTful APIs for building Cloud Native Applications.
This document covers RESTful API development using platforms (Spring Boot, Node.js, Python) as well as how to run them on Kubernetes.
Contents
Section titled “Contents” Container Overview of container technology and using Docker
Kubernetes Core Kubernetes concepts and operations
REST API RESTful API design guide
cf) https://docs.microsoft.com/ko-kr/dotnet/architecture/cloud-native/definition cf) https://github.com/cncf/foundation/blob/master/charter.md
Twelve-Factor for Application
Section titled “Twelve-Factor for Application”| Factor | Description |
|---|---|
| 1. Codebase | A single codebase for each microservice, stored in its own repository. It is tracked using version control and can be deployed to multiple environments (Dev, Staging, Production). |
| 2. Dependencies | Each service isolates and packages its own dependencies, embracing changes without affecting the entire system. |
| 3. Config | Configuration information is applied by the service and managed through configuration management tools external to the code. The same deployment artifact can be propagated/applied per environment (Dev/Staging/Prod) simply by modifying the configuration. |
| 4. Backing Services | Also called Backend Services or Backing Services, auxiliary resources (data stores, caches, message brokers) should be exposed via addressable URLs. This lets resources be decoupled from the application and swapped with each other. |
| 5. Build, Release, Run | Each release must enforce strict separation across the build, release, and run stages. Each tag must be assigned a unique ID and support rollback. Modern CI/CD systems can help satisfy this principle. |
| 6. Processes | Each microservice should run in its own process, isolated from other running services. It must be able to operate without storing state for continuous business processing (Stateless). |
| 7. Port Binding | Each service must expose its interfaces and functionality by exposing a port. |
| 8. Concurrency | It must be possible to scale out according to the Application Process Model. |
| 9. Disposability | Service instances must be disposable, favoring fast startup to increase scaling opportunities and shutting down gracefully to leave the system in a correct state. |
| 10. Dev/Prod parity | Keep environments (Dev/Prod) as similar as possible throughout the application lifecycle to minimize cost. |
| 11. Logging | Treat logs generated by the microservice as event streams. In other words, logs should be analyzable. |
| 12. Admin Processes | Run admin/management tasks as processes. Tasks may include data cleanup and analysis for reports. The tools that run these tasks should be invoked in production but invoked separately from the application. |
Codebase
Section titled “Codebase”- One codebase under version control, deployed many times
- There is always a one-to-one relationship between the codebase and the app

Dependencies
Section titled “Dependencies”- An application’s dependencies must be declared explicitly
- All dependent libraries must be downloadable from a library repository using a dependency management tool such as Apache Maven or Gradle
dependencies {implementation('org.springframework.boot:spring-boot-starter-web')implementation('org.springframework.boot:spring-boot-starter-actuator')implementation('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')implementation('io.micrometer:micrometer-registry-prometheus')compileOnly('org.projectlombok:lombok')testImplementation('org.springframework.boot:spring-boot-starter-test')}<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-webflux</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.2.0</version></dependency>
Config
Section titled “Config”- Configuration information is stored in the runtime environment
- Configuration is strictly separated from application code
- Configuration is everything that can vary between deployments (staging, production, development, etc.), such as DB info, external service credentials, host names, etc.
- Store configuration in environment variables (env)
application-prod.properties
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialectspring.datasource.url=jdbc:mariadb://localhost:3306/employeesspring.datasource.username=rootspring.datasource.password=${DB_PASSWORD}spring.datasource.driver-class-name=org.mariadb.jdbc.Driverapplication-dev.properties
spring.datasource.url=jdbc:h2:mem:employeesspring.datasource.driverClassName=org.h2.Driverspring.datasource.username=saspring.datasource.password=spring.jpa.database-platform=org.hibernate.dialect.H2DialectBacking Services
Section titled “Backing Services”- A backing service is treated as a resource attached on demand
- Backing services include databases, API-based RESTful web services, SMTP servers, FTP servers, etc.
- Backing services are regarded as resources of the application
- You should be able to swap the embedded SQL used in the test environment for MySQL in the staging environment
Build, Release, Run
Section titled “Build, Release, Run”- Thoroughly separated build and run stages
- The codebase is transformed into a (non-development) deploy through three stages
- Build stage : takes the source code, compiles it, and produces a single package
- Release stage : combines the build with configuration information
- The release version is fully ready to operate in the runtime environment
- Identifiers such as semantic versioning are assigned; these versions are used to roll back
- Run stage : usually called the runtime : selects one of the release versions and runs the application on top of the runtime environment
Processes
Section titled “Processes”- Each process must not interfere with the others. When one terminates, there must be no physical impact on other apps
(In a WAS, the JVM is shared per Application Context, so interference occurs) - Resources used must be usable independently.
- App-1 : 2 Instances (2core, 4GB Memory)
- App-2 : 4 Instances (1core, 1GB Memory)
Port Binding
Section titled “Port Binding”- A service binds to a port and exposes itself externally
- It is fully self-contained, including its own web server, so there is no need to add a separate web server to the runtime environment
Concurrency
Section titled “Concurrency”- Scale horizontally through the process model
- The application must be able to scale out processes or threads horizontally and run them in parallel as needed
- Long-running data processing tasks should be assigned to a thread pool and executed via a thread executor
- For example, HTTP requests should be handled by servlet threads, while time-consuming tasks should be handled by worker threads
Disposability
Section titled “Disposability”- Maximize robustness with fast startup and graceful shutdown
- The application can be stopped at any time during process execution, and when stopped it can perform all tasks that must be handled and then shut down cleanly
- It should start up in as short a time as possible
Dev/Prod parity
Section titled “Dev/Prod parity”- Keep the development, staging, and production environments as similar as possible
- Parity that keeps development and production environments as identical as possible should prevent divergence
- Three differences to keep in mind
- Time gap : developers must deploy changes to production quickly
- Personnel gap : the developer who makes the code change should also be able to deploy to production and monitor it
- Tools gap : the technologies and frameworks used in each runtime environment should be configured identically
Logging
Section titled “Logging”- Treat logs as event streams
- Write logs to stdout
- The application should not be involved in storing log files
- Log aggregation and storage should be handled by the runtime environment, not the application
Admin Processes
Section titled “Admin Processes”- Run admin/maintenance tasks as one-off processes
- Run them in the same environment as the running processes
- Admin code must be deployed together with the application code