나를 위한 면접 (Backend Developer Interview Questions)
· 약 27분
BE Interview Questions를 아는 만큼 답해보았다 지극히 주관적이라 정답이 아닐 수 있습니다
Why are global and static objects evil?
- 전역변수는 어디서 변경되었는지 추적이 힘듦
- 그리고 자바의 경우 콜스택이 끝나면 비워지는 지역변수와 달리 메모리의 static 영역에 계속 상주해 있음
Tell me about Inversion of Control and how does it improve the design of code
- 클래스 안에 다른 클래스의 기능이 필요하다면 내부에서 생성자를 이용해 두 클래스 간의 종속이 생겨버리는데
- IoC를 통한다면 DI 패턴으로 구현해
new A(new B())
처럼 종속성을 분리시킬 수 있음 - TypeHint를 통해 의존성을 확인할 수 있으므로 더 직관적이기도 하다
- What is Inversion of Control?
Active-Record is the design pattern that promotes objects to include functions such as Insert, Update, and Delete, and properties that correspond to the columns in some underlying database table. In your opinion and experience, which are the limits and pitfalls of the this pattern?
- 장점
- 하나의 구조로 모든 모델을 제어할 수 있게 해준다.
- 또한 모든 DB 마다 다른 쿼리문 (예를 들어 페이징)을 손쉽게 처리할 수도 있다.
- 무엇보다 엄청 빠르게 DB 조작이 가능해진다.
- 단점
- DB를 잊어버리게 되는 것 아닐까? ActiveRecord로 개발을 시작하는 건 아니다라고 본다.
- 여러 테이블의 조인이 힘들고 (조인 조건을 만족하기 위해) 계산이 들어간 쿼리문이라면 어차피 RAW 쿼리를 날려야한다.
- 프로시져를 사용할 수도 없고, 관계형 모델들은 select를 키값을 통해 여러 번 select 한 뒤 합쳐주는 것 뿐이라 성능상의 이슈도 있다.
- 결국 필요한 곳에서만 (RESTful 구조의) 사용해서 개발하는 게 좋을 것 같다
Data-Mapper is a design pattern that promotes the use of a layer of Mappers that moves data between objects and a database while keeping them independent of each other and the mapper itself. On the contrary, in Active-Record objects directly incorporate operations for persisting themselves to a database, and properties corresponding to the underlying database tables. Do you have an opinion on those patterns? When would you use one against the other?
The big benefit of the Data Mapper pattern is, your domain objects don't need to know anything about how they are stored in the database. This means that your objects will be lighter because they don't have to inherit the full ORM, but also there will be a stricter, more formal process for interacting with the database because you can't just call the save() method anywhere in your code
- 데이터 매퍼는 DB 스키마와 독립적인 모델을 갖고 싶을 때 사용한다
- ActiveRecord의 속도보다 성능이 필요한 경우 사용하면 된다.
- What's the difference between Active Record and Data Mapper
Why it is often said that the introduction of null is a "Billion dollar mistake"? Would you discuss the techniques to avoid it, such as the Null Object Pattern introduced by the GOF book, or Option types?
- null 로 변수를 생성하는 건 안하는 거랑 똑같지만, 안 해주면 프로그램이 뻗어버려서 null 타입 체크를 하거나 default값을 추가한다.
- 10억 달러짜리 실수
Many state that, in Object-Oriented Programming, Composition is often a better option than Inheritance. What's you opinion?
- 부모-자식 관계면 상속이지만, Has 관계이면 컴포지션
- 잘못 알려진 디자인 패턴의 두번째 원칙
What is an Anti-corruption Layer?
- 추상화 한 레이어를 하나 더 두고 하위 도메인들을 쉽게 접근할 수 있게 하는 방법, facade 처럼
Singleton is a design pattern that restricts the instantiation of a class to one single object. Writing a Thread-Safe Singleton class is not so obvious. Would you try?
Volatile
How would you deal with Dependency Hell?
- 의존성 컨테이너를 사용한다.
- 패키지 매니저툴을 이용하며 버전을 명시한다.
- maven, composer, npm 등등
Is goto evil?
- 적절하게, 가독성 있게 사용하면 괜찮다.
- 리눅스 커널 이런 느낌으로
Code Design
It is often heard that one of the most important goals in Object-Oriented Design is to have High Cohesion and Loose Coupling. What does it mean? Why is it that important and how is it achieved?
- Coupling
- 모듈 간에 상호 의존하는 정도
- 각 모듈 간의 결합도가 약해야 하며 의존하는 모듈이 적어야한다.
- 결합도가 강하면 시 스템 구현 및 유지보수 작업이 어렵다.
- Cohesion
- 정보 은닉 개념을 확장한 것
- 명령어나 호출문 등 모듈의 내부 요소들의 서로 관련되어 있는 정도
- 모듈이 독립적인 기능으로 정의되어 있는 정도
- 독립적인 모듈이 되기 위해서는 각 모듈의 응집도가 강해야한다
Why does array index start with '0' in most of languages?
- 배열이 참조하는 메모리의 위치를 나타내므로 (시작 위치에서의 기준점)
Are comments in code useful? Some say they should be avoided as much as possible, and hopefully made unnecessary
- 변수명, 메소드명으로 명확하게 표현할 수 있으면 좋은데, 그러긴 현실적으로 힘들고
- JSDoc 같은 구문으로 주석을 단다면 참조하는 다른 소스에서도 hover만으로 모든 설명을 볼 수 있어서도 좋고
What is the difference between design and architecture?
- Software architecture is more about the design of the entire system, while software design emphasizes on module / component / class level.
- Architecture: MVC, 3-tier layered design, etc.
- Design: What are the responsibilities, functions, of module x? Of class Y? What can it do, and what not?
- Software Design vs. Software Architecture
C++ supports multiple inheritance, and Java allows a class to implement multiple interfaces. What impact does using these facilities have on orthogonality? Is there a difference in impact between using multiple inheritance and multiple interfaces? Is there a difference between using delegation and using inheritance?
- implements가 좀 더 유연하다 클래스 안에서 직접 구현해야되는거니까
Pros and cons of holding domain logic in Stored Procedures
- 장점
- 한 번 만든걸 계속 호출해서 쓸 수 있음
- 컴파일 언어의 경우 쿼리만 변경하는거니 유지보수가 좋을 수 있음
- 계산이 들어가는 쿼리의 경우 SP는 캐싱되므로 이만한게 없음
- 단점
- DB에 완전 종속됨
- DBA가 있어야함
- git에서 변경점 추적 불가능
In your opinion, why have Object-Oriented Design dominated the market for so many years?
- 관심사의 분리
Languages
Tell me the 3 worse defects of your preferred language
- PHP
- 컴파일 언어가 아니라 느림 (PHP7부턴 달라짐, OpCache를 사용하면 되긴함)
- 쓰레드가 없음 (PHP React나 Guzzle promise 같은 걸 사용하면 event driven 방식으로 되긴 함)
- 인식이 안 좋음
- 함수명이 너무 제각각임 (어떤 건 snake_case 어떤건 붙혀서)
Why is there a rising interest on Functional Programming?
- 각 실행 단계를 이뮤터블로 만들어 Side effect를 없앤다.
- 테스트가 쉽다.
- 가독성이 높아진다
What is a closure, and what is useful for? What's in common between closures and classes?
- FE 인터뷰에 정리해놓았다
What are generics useful for?
- 타입 캐스팅
What are high-order functions? What are they useful for?
- 함수를 파라미터로 전달받거나, 함수를 리턴하는 함수로 다형성을 지원해 재사용이 가능하다
What does it mean when a language treats functions as first-class citizens?
- 변수나 데이터에 할당 가능
- 파라미터로 넘길 수 있어야함
- 리턴값으로 리턴이 가능해야함
Show me an example where an Anonymous Function can be useful
- 모든 콜백에서 유용함
Whats the Stack and what's the Heap? What's a Stack Overflow?
- Stack: LIFO
- Heap: 최소 또는 최대 값이 루트에 있는 완전 이진 트리
- Stack Overflow: 지식인 또는 Stack이 꽉 찼는데 삽입하려 들 때
Some languages, especially the ones that promote a Functional approach, allow a technique called Pattern Matching. Do you know it? How is Pattern Matching different from Switch clauses?
- C#에서
is
구문을 말하는건가? switch
는 하나의 타입에서만 비교가 가능한데, 패턴매칭을 쓰면 더 동적으로 비교가 가능하다
If Cat is an Animal
is TakeCare<Cat> a TakeCare<Animal> ?
- 같지는 않지만 집어넣을 수는 있다
In the last years there has been a lot of hype on Node. What's your opinion on the use in the back end of a language that was initially conceived to run in the browser?
- Atwood's Law: any application that can be written in JavaScript, will eventually be written in JavaScript.
참고
Web development
Why first-party cookies and third-party cookies are treated so differently?
- first-party cookie
- 자사 쿠키는 방문하는 웹사이트가 설정하며 해당 사이트에서만 사용
- third-party cookie
- 타사 쿠키에서 분석 등의 용도로 사용
How would you manage Web Services API versioning?
- 시맨틱 버저닝
From a Back End perspective, are there any disadvantages or drawbacks on the adoption of Single Page Applications?
- 백엔드 관점
- 장점: 웹을 SPA로 가면 API가 필요하고, 디바이스 확장성에 대해 좋음
- 단점: SEO 때문에 어차피 SSR 해줘야됨
Why do we usually put so much effort for having stateless services? What's so good in stateless code and why and when statefullness is bad?
REST and SOAP: when would you choose one, and when the other?
In Web development, Model-View Controller and Model-View-View-Model approaches are very common, both in the Back End and in the Front End. What are they, and why are they advisable?
- MVC
- Controller로 사용자의 입력이 들어옵니다.
- Controller는 Model을 데이터 업데이트 및 불러오고
- Model은 해당 데이터를 보여줄 View를 선택해서 화면에 보여주게 됩니다.
- MVVM
- View에 입력이 들어오면 Command 패턴으로 ViewModel에 명령을 합니다.
- ViewModel은 필요한 데이터를 Model에 요청 합니다.
- Model은 ViewModel에 필요한 데이터를 응답 합니다.
- ViewModel은 응답 받은 데이터를 가공해서 저장 합니다.
- View는 ViewModel과의 Data Binding으로 인해 자동으로 갱신 됩니다.
- MVC, MVP, MVVM 비교
Databases
How would you migrate an application from a database to another, for example from MySQL to PostgreSQL? If you had to manage that project, which issues would you expect to face?
- Oracle => MySQL
- date 처리에서 애를 먹었는데, 덤프를 바로 옮기지 않고 데이터를 가져와 다시 넣는 방식으로 마이그레이션 했다
- Right join (+ 조인)을 Left로 바꾸는데 시간이 걸렸다
- MySQL => Maria
- 완벽 호환, utf8mb4로 콜렉션과 차셋도 바꿔줌