0Pricing
API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) · 강의

리액티브 기반 이해하기

Spring Cloud Gateway가 비차단 리액티브 스택을 기반으로 구축된 이유와 이것이 게이트웨이를 통과하는 요청 흐름에 어떤 의미를 갖는지 알아봅니다.

리액티브 기반 이해하기은(는) CoddyKit의 무료 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

A Different Kind of Server

Unlike a traditional Spring MVC app, Spring Cloud Gateway runs on Spring WebFlux and Project Reactor. It uses a non-blocking, event-loop server (Netty) instead of one thread per request.

This design lets the gateway handle thousands of concurrent connections with very few threads.

Blocking vs Non-Blocking

In a blocking model, a thread waits idle while a backend responds. In a non-blocking model, the thread is freed and notified later when data is ready.

  • Blocking: 1 thread tied up per in-flight request
  • Non-blocking: a handful of threads serve many requests

Mono and Flux

Reactor's core types describe asynchronous results:

  • Mono<T> emits 0 or 1 value
  • Flux<T> emits 0 to many values

The gateway returns a Mono<Void> when a request finishes processing.

Mono<String> name = Mono.just("gateway");
Flux<Integer> nums = Flux.just(1, 2, 3);

Nothing Happens Until Subscribe

Reactive streams are lazy. A Mono or Flux does nothing until something subscribes. In the gateway, the framework subscribes for you when a request arrives.

Mono<String> greeting = Mono.fromSupplier(() -> "hello");
// runs only when subscribed:
greeting.subscribe(System.out::println);

The Reactive Web Stack

The starter spring-cloud-starter-gateway pulls in WebFlux automatically. You must not add spring-boot-starter-web (the servlet/MVC stack) or startup will fail with a conflict.

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-gateway</artifactId>
</dependency>

The ServerWebExchange

Every request is wrapped in a ServerWebExchange, which holds the request and response. Filters read and mutate this exchange as the request flows through.

// inside a filter
ServerHttpRequest request = exchange.getRequest();
String path = request.getURI().getPath();

The Filter Chain

A request passes through an ordered chain. Each filter can act, then call chain.filter(exchange) to continue, and run more logic after the downstream response returns.

return chain.filter(exchange)
    .then(Mono.fromRunnable(() ->
        System.out.println("response sent")));

Why Reactive Fits a Gateway

A gateway spends most of its time waiting on the network for upstream services. Non-blocking I/O is ideal here: threads are not wasted waiting, so the gateway stays responsive under heavy load.

Avoid Blocking Calls

Calling a blocking JDBC driver or Thread.sleep inside a filter stalls the event loop and hurts every request. If you must block, offload to a bounded scheduler.

Mono.fromCallable(() -> blockingLookup())
    .subscribeOn(Schedulers.boundedElastic());

Operators Transform Streams

Operators like map, flatMap, and filter reshape the data flowing through a stream without blocking.

Flux.just(1, 2, 3, 4)
    .filter(n -> n % 2 == 0)
    .map(n -> n * 10)
    .subscribe(System.out::println); // 20, 40

Mental Model

Think of the gateway as a pipeline of asynchronous steps. A request enters, flows through predicates and filters, is forwarded reactively, and the response streams back through the same chain in reverse.

Quick Check

What underlying web stack does Spring Cloud Gateway run on?

Recap

You now understand the reactive foundation of the gateway:

  • Non-blocking I/O on Netty handles high concurrency
  • Mono and Flux model async results and are lazy
  • Each request is a ServerWebExchange flowing through a filter chain
  • Never block the event loop

This mindset underpins routes, predicates, and filters you build next.

자주 묻는 질문

“리액티브 기반 이해하기” 강의는 무료인가요?

네 — “리액티브 기반 이해하기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의 전체를 잠금 해제할 수 있습니다. API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의에는 총 4개의 강의가 포함되어 있습니다.

“리액티브 기반 이해하기”에서 뭘 배우나요?

Spring Cloud Gateway가 비차단 리액티브 스택을 기반으로 구축된 이유와 이것이 게이트웨이를 통과하는 요청 흐름에 어떤 의미를 갖는지 알아봅니다. 브라우저에서 직접 실행하는 실습 코드로 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“리액티브 기반 이해하기” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 게이트웨이와 기존 마이크로서비스 비교
  2. 기본 게이트웨이 프로젝트 설정
  3. 경로 및 조건자 정의
  4. 리액티브 기반 이해하기
← API Gateway & Reverse Proxy (Nginx + Spring Cloud Gateway)(으)로 돌아가기