> For the complete documentation index, see [llms.txt](https://leehyokyun.gitbook.io/openbook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://leehyokyun.gitbook.io/openbook/1-5.-ipc-inter-process-communication.md).

# 1-5. IPC (Inter-Process Communication)

서로 다른 체계에서 통신하는 방식, IPC에 대하여

### 1. Process IPC vs Event Driven Architecturing (개념 비교 및 출발점)

* IPC와 EDA를 구분하는 출발점은 분리된 프로세스 간의 통신 방법(What)과 그 구체적인 방안(How)이다.
* IPC(Inter Process Communication)는 격리된 프로세스 혹은 서비스 간에 데이터를 주고받는 메커니즘을 의미한다.
* 프로세스는 기본적으로 메모리 공간이 분리되어 서로 직접 접근이 불가능하고 독립적으로 실행되므로, 데이터를 주고받으려면 구체적인 통신 방법이 필연적으로 요구된다.
* EDA(Event Driven Architecture)는 시스템이 이벤트를 중심으로 동작하도록 설계된 체계다.
* 프로세스 및 서비스 간의 통신 방법에만 국한된 개념이라기보다는, 시스템 내부에서의 주된 통신 방법 중 이벤트 기반 비동기 메시징 방식을 활용한 아키텍칭에 가까운 개념이다.
* Kafka 기반 EDA 예시:
  * OrderService가 Kafka에 이벤트를 발행(Publish)한다.
  * PaymentService가 Kafka Consumer로서 이를 수신한다.
  * ShippingService가 Kafka Consumer로서 이를 수신한다.
  * 이는 전형적인 EDA 구조에 해당한다.

### 2. OS 레벨 IPC와 네트워크/MSA 레벨 IPC 분류

* OS 레벨 IPC (같은 머신 내 통신):
  * Pipe: 단방향 데이터 흐름을 가지는 통신 방식이다.
  * Named Pipe: 파일처럼 접근이 가능한 확장된 Pipe 방식이다.
  * Message Queue: OS 커널이 메시지를 관리하고 저장하는 형태다.
  * Shared Memory: 프로세스들이 공유하는 메모리 영역을 직접 할당하여 통신한다.
* 네트워크/MSA 레벨 IPC (다른 머신 혹은 분리된 서비스 간 통신):
  * MSA에서 말하는 IPC는 대부분 이 영역을 의미한다.
  * HTTP/REST: 동기 요청-응답 기반의 대중적인 통신 방식이다.
  * gRPC: 구글에서 개발한 고성능 RPC(Remote Procedure Call) 체계다.
  * Message Broker: Kafka, RabbitMQ 등을 활용한 비동기 메시지 전달 방식이다.

### 3. 소켓(Socket)의 정의와 계층별 추상화 인터페이스 역할

* 소켓은 사용에 따라 응용 계층 혹은 IPC 전송 계층으로 사용되는 추상화된 인터페이스다.
* 예시 1 (TCP 소켓):
  * socket() 생성을 거쳐 TCP 연결을 수립한 후 send()와 recv() 연산을 진행한다.
  * 여기서 TCP는 네트워크 전송 계층이고, 소켓은 그 전송 계층을 사용하는 인터페이스 역할을 수행한다.
  * 즉, HTTP나 Redis 프로토콜 등 응용 계층 데이터를 전달하는 안전한 통로가 된다.
* 예시 2 (Unix Domain Socket):
  * 네트워크 장비나 인프라 없이 동일한 호스트(같은 머신) 내에서만 사용된다.
  * TCP/IP 프로토콜 스택을 거치지 않으므로 네트워크 전송 계층은 존재하지 않는다.
  * 동일한 컨테이너(호스트) 환경에서는 네트워크 전송 계층이 없는 대신, 커널이 직접 제공하는 IPC 전송 계층 역할을 전담한다.
  * 응용 계층의 HTTP 기반 데이터 내역을 쓰고 전송하기 위한 통신 메커니즘으로 기능하며, 응용 계층 데이터(HTTP API 요청)를 주고받는 통로 역할을 수행한다.

### 4. Process IPC for Docker CLI and Docker Daemon

* Docker CLI와 Docker Daemon의 통신은 동일한 호스트 환경 내부에서 이루어지는 IPC(HTTP + Unix Domain Socket) 구조다.
* Daemon 측에서는 OS 커널 메모리 버퍼를 통해 데이터를 안전하게 전송받아 처리한다.
* 구체적인 메커니즘:
  * docker.sock이라는 특정 파일을 매개체로 활용하여 인터페이스를 통한 Unix Domain Socket IPC를 진행한다.
  * 전체 통신 흐름 구조는 다음과 같다:
    * \[Docker CLI] <-- HTTP 요청 --> \[Unix Domain Socket IPC / 파일 / 커널] <-- HTTP 응답 --> \[Docker Daemon]
  * Docker CLI가 docker.sock 파일을 열고 연결하여 HTTP 요청 형태로 데이터를 물리적으로 write(그 자체가 Socket 연산)한다.
  * Daemon 측에서는 이 docker.sock 파일을 IPC용 통신 채널로 활용하여 연산을 대기한다.
  * 커널의 Socket Buffer에 데이터를 전달하고, 이 생성된 Socket Buffer를 Daemon 측에서 그대로 읽어 들여 요청을 처리하고 응답을 수행한다.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://leehyokyun.gitbook.io/openbook/1-5.-ipc-inter-process-communication.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
