Controller, Service, Manager 차이?

KUN·2025년 3월 31일

깃헙이나 구조를 제작하다가 Controller 와 Service 그리고 Manager 라는 단어를 많이 보게 되었는데,
이것에 대한 개념적인 차이가 너무 헷갈려서 그것에 대해 조사하고 공부해봤습니다.

원래 내가 알던 사실은
Controller : 중재자
Service : 비즈니스 로직 처리
Manager : 서비스를 호출하여 복잡한 로직 처리

즉, Controller -> Manager -> Service 순서인 줄 알았습니다.

예를 들어, Controller 가 외부 클라이언트에게 값을 받고 Manager 에게 하달 합니다.
Manager 은 여러개의 서비스를 조합해서 결과 값을 Controller 에 리턴 합니다.
Controller 는 최종 사용자에게 값을 넘겨줍니다.

맞는 것 같으면서도 아닌 것 같아서...
왜냐하면 Controller 에서 Manager 통할 필요없이 바로 Service를 할당을 해도 되는데 굳이? 매니저를 추가할 이유가 있나? 라는 궁금증이 생겨서 계속 찾는 도중에 저랑 같은 문제에 대해서 알아보신 분이 있더라구요?

https://blog.naver.com/syung1104/220833979220

네이밍시 무심결에 자주 사용하는 세가지 개념.

Controller, Service, Manager
* 여기서의 Service는 안드로이드에서의 그 'Service' 컴포넌트와는 다르다.
대부분의 프로젝트에서 세개의 개념 자체가 굉장히 혼용되고 있다.
(특히나 안드로이드 프로젝트에서는 안드로이드 컴포넌트 중 하나인 Service 때문에 더욱더 혼용되기도 한다.)

이 세가지 개념은 잘못 이해하면 잘못된 네이밍을 유발시켜 가독성과 정체성에 문제 생길 수 있기 때문에 개념을 제대로 파악하는 것이 중요하다.
 
[출처] [OOP] Controller, Service, Manager의 개념적 차이|작성자 팔렛의 시선
There are certain patterns and guidelines behind these term, which is where I usually base it on:

Controller is based on the Model-View-Controller design pattern and should be used explicitly for the classes that implement the controller functionality based on this design pattern.
E.g. if you are using Spring MVC and you extend from one of the Controller classes.

Service is a little less specific,
but I recommend basing the implementation on the Service Layer pattern from "Patterns of Enterprise Application Architecture". 
Basically where a controller is more platform specific (e.g. transport via HTTP and rendering of Hypertext, 
usually HTML for web based controllers) a service shouldn't have to know about who is using it and how.
You are just providing a uniform interface that can be used in turn by e.g. a web controller.

Managers well... manage stuff. 
Connections, 
application context, 
sessions; 
usually as a central location where components throughout the application can talk to.

예를 들어 계산대라고 했을 때
Controller는 고객이 계산하려는 요청을 받고, 그 요청을 Service에 넘깁니다.
Service는 계산을 할 때 필요한 자원(예: 가격 확인, 재고 확인 등)을 Manager를 통해 요청할 수 있습니다.
Manager는 이 자원들이 제대로 준비되었는지 관리하고, Service가 필요로 하는 자원을 제공합니다.

대충 이런식으로 정리될 수 있습니다.
Manager 가 외부 시스템을 이용한다는 것.

그리고 보통 계층형 구조에서 주로 쓰인다고 하는데... 음 DDD 에서도 많이 봤었던 것 같습니다.

CustomerService

	private UserRepository
    private S3Manager
    private EmailManager

public void signUp(User user) {
    // 회원 저장
    userRepository.save(user);

    // 프로필 이미지 S3에 업로드
    s3Manager.uploadProfileImage(user.getId(), user.getProfileImage());

    // 환영 이메일 발송
    emailManager.sendWelcomeEmail(user.getEmail());
}

보통 이런식으로 CustomerService 에서 회원가입을 하려고 할때 Repository 로 회원을 저장하고 ( DB )
S3에 이미지를 업로드 하기 위해서는 S3Manager 을 사용
또한 이메일을 발송하기 위해 EmailManager 사용

완벽하게 이해한건 아니지만, 어떤 식으로 사용하는지 알겠습니다.
signUp 에서는 User 의 새로운 정보를 받아서 DB에 저장하고 ( 물론 다른 비즈니스 로직은 있어야 겠지만 다 생략 )
프로필은 S3 매니저를 통해 유저의 프로필 이미지 등록
이메일은 이메일 매니저를 통해 이메일을 보낸다.

오늘 알게 된 점
Controller 와 Service 는 외부통신을 하지 않고
Manager 은 외부통신을 실행한다.

profile
배우노라, 실험하노라, 기록하노라

0개의 댓글