# Performance Optimization (Laravel) > 쿼리 최적화, N+1 문제, eager loading, lazy loading, 캐싱 전략, 데이터베이스 인덱싱, 프로파일링 도구 - 22 면접 질문 - Senior - [면접 질문: Laravel](https://sharpskill.dev/ko/technologies/laravel/interview-questions.md) ## 1. Laravel에서 N+1 문제란 무엇입니까? **답변** N+1 문제는 Eloquent가 컬렉션을 가져오기 위해 하나의 쿼리를 실행한 다음 관계를 로드하기 위해 항목마다 추가 쿼리를 실행할 때 발생합니다. 이는 데이터베이스 접근을 배가시키고 대규모에서 성능을 크게 저하시킵니다. with()를 사용한 eager loading을 적용하면 N개의 쿼리 대신 하나의 추가 쿼리로 모든 관계를 로드합니다. ## 2. 관계를 로드할 때 N+1 문제를 해결하려면 어떤 메서드를 사용해야 합니까? **답변** with() 메서드는 eager loading을 수행하여 관계를 하나의 추가 쿼리로 로드합니다. 관계에 접근할 때 모델마다 쿼리를 실행하는 대신 모든 관계를 미리 로드합니다. 이는 SQL 쿼리 수를 크게 줄이고 성능을 향상시킵니다. ## 3. eager loading과 lazy loading의 차이점은 무엇입니까? **답변** eager loading은 with()를 통해 메인 쿼리와 함께 관계를 즉시 로드하는 반면, lazy loading은 첫 접근 시 필요할 때 관계를 로드합니다. lazy loading은 루프 안에서 관계에 접근하면 N+1 문제를 일으킬 수 있습니다. 관계를 사용할 예정이라면 여러 쿼리를 피하기 위해 eager loading이 권장됩니다. ## 19개 추가 질문 이용 가능 - Laravel에서 Cache::remember()의 역할은 무엇입니까? - Cache::remember()와 Cache::rememberForever()의 차이점은 무엇입니까? 무료로 가입하기: https://sharpskill.dev/ko/login ## 기타 Laravel 면접 주제 - [PHP 기초](https://sharpskill.dev/ko/technologies/laravel/interview-questions/php-basics.md): 25개 질문, Junior - [PHP 객체지향 기초](https://sharpskill.dev/ko/technologies/laravel/interview-questions/php-oop-essentials.md): 20개 질문, Junior - [Composer & Autoloading](https://sharpskill.dev/ko/technologies/laravel/interview-questions/composer-autoloading.md): 18개 질문, Junior - [Laravel 기초](https://sharpskill.dev/ko/technologies/laravel/interview-questions/laravel-fundamentals.md): 20개 질문, Junior - [Laravel 라우팅](https://sharpskill.dev/ko/technologies/laravel/interview-questions/laravel-routing.md): 20개 질문, Junior - [Blade Templates](https://sharpskill.dev/ko/technologies/laravel/interview-questions/blade-templates.md): 18개 질문, Junior - [Request & Response](https://sharpskill.dev/ko/technologies/laravel/interview-questions/request-response.md): 20개 질문, Junior - [Eloquent ORM 기초](https://sharpskill.dev/ko/technologies/laravel/interview-questions/eloquent-orm-basics.md): 22개 질문, Junior - [Eloquent Relationships](https://sharpskill.dev/ko/technologies/laravel/interview-questions/eloquent-relationships.md): 25개 질문, Mid-Level - [Migrations & Schema Builder](https://sharpskill.dev/ko/technologies/laravel/interview-questions/database-migrations.md): 20개 질문, Mid-Level - [유효성 검사와 폼](https://sharpskill.dev/ko/technologies/laravel/interview-questions/validation-forms.md): 22개 질문, Mid-Level - [인증](https://sharpskill.dev/ko/technologies/laravel/interview-questions/authentication.md): 20개 질문, Mid-Level - [인가와 Policies](https://sharpskill.dev/ko/technologies/laravel/interview-questions/authorization-policies.md): 18개 질문, Mid-Level - [API Resources & Authentication](https://sharpskill.dev/ko/technologies/laravel/interview-questions/api-resources-authentication.md): 26개 질문, Mid-Level - [미들웨어](https://sharpskill.dev/ko/technologies/laravel/interview-questions/middleware.md): 18개 질문, Mid-Level - [Service Container & DI](https://sharpskill.dev/ko/technologies/laravel/interview-questions/service-container-di.md): 20개 질문, Mid-Level - [Queues & Jobs](https://sharpskill.dev/ko/technologies/laravel/interview-questions/queues-jobs.md): 22개 질문, Mid-Level - [Events & Listeners](https://sharpskill.dev/ko/technologies/laravel/interview-questions/events-listeners.md): 18개 질문, Mid-Level - [알림 및 메일](https://sharpskill.dev/ko/technologies/laravel/interview-questions/notifications-mail.md): 20개 질문, Mid-Level - [File Storage](https://sharpskill.dev/ko/technologies/laravel/interview-questions/file-storage.md): 18개 질문, Mid-Level - [Testing & PHPUnit](https://sharpskill.dev/ko/technologies/laravel/interview-questions/testing-phpunit.md): 24개 질문, Mid-Level - [Caching](https://sharpskill.dev/ko/technologies/laravel/interview-questions/caching.md): 18개 질문, Mid-Level - [Livewire & Inertia](https://sharpskill.dev/ko/technologies/laravel/interview-questions/livewire-inertia.md): 20개 질문, Mid-Level - [Eloquent Advanced](https://sharpskill.dev/ko/technologies/laravel/interview-questions/eloquent-advanced.md): 24개 질문, Senior - [Repository Pattern](https://sharpskill.dev/ko/technologies/laravel/interview-questions/repository-pattern.md): 20개 질문, Senior - [Laravel 패키지](https://sharpskill.dev/ko/technologies/laravel/interview-questions/laravel-packages.md): 20개 질문, Senior - [Security Best Practices](https://sharpskill.dev/ko/technologies/laravel/interview-questions/security-best-practices.md): 22개 질문, Senior - [Laravel Octane](https://sharpskill.dev/ko/technologies/laravel/interview-questions/laravel-octane.md): 18개 질문, Senior - [Laravel Distributed Systems](https://sharpskill.dev/ko/technologies/laravel/interview-questions/laravel-distributed-systems.md): 22개 질문, Senior - [Observability & Monitoring](https://sharpskill.dev/ko/technologies/laravel/interview-questions/observability-monitoring.md): 20개 질문, Senior - [Deployment & DevOps](https://sharpskill.dev/ko/technologies/laravel/interview-questions/deployment-devops.md): 20개 질문, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/ko/technologies/laravel/interview-questions/performance-optimization