# Laravel Distributed Systems (Laravel) > การสื่อสารแบบ queue-based, events, outbox pattern, idempotency, retries, circuit breaker, สัญญา API, การทำเวอร์ชัน, พื้นฐาน Saga - 22 คำถามสัมภาษณ์ - Senior - [คำถามสัมภาษณ์: Laravel](https://sharpskill.dev/th/technologies/laravel/interview-questions.md) ## 1. outbox pattern ในระบบแบบกระจายของ Laravel คืออะไร? **คำตอบ** outbox pattern จะจัดเก็บ messages/events ลงในตาราง database ภายใน transaction เดียวกันกับข้อมูลทางธุรกิจ จากนั้นส่งออกแบบ asynchronous ในกระบวนการที่แยกต่างหาก ซึ่งรับประกันว่า messages จะถูกส่งเสมอแม้ระบบจะ crash หลังจาก commit DB แล้ว ShouldQueueAfterCommit ของ Laravel เป็นการ implement pattern นี้แบบบางส่วน เนื่องจากจะ dispatch job หลังจาก commit transaction เท่านั้น จึงหลีกเลี่ยง race condition ที่ job ทำงานก่อนที่ข้อมูลจะพร้อมใช้งาน ## 2. ความแตกต่างหลักระหว่าง ShouldQueue และ ShouldQueueAfterCommit คืออะไร? **คำตอบ** ShouldQueue จะ dispatch job ไปยัง queue ทันที แม้ว่า transaction DB จะยังไม่ถูก commit ซึ่งอาจทำให้เกิด race condition ส่วน ShouldQueueAfterCommit จะรอให้ transaction DB ทั้งหมดถูก commit ก่อนที่จะ dispatch job เพื่อให้แน่ใจว่าข้อมูลพร้อมใช้งานเมื่อ job ทำงาน ใช้ ShouldQueueAfterCommit สำหรับ job ที่ขึ้นอยู่กับข้อมูลที่เพิ่งสร้างหรือแก้ไขใน transaction เช่น job ส่ง email หลังจากสร้างคำสั่งซื้อ ## 3. idempotence ในบริบทของระบบแบบกระจายของ Laravel คืออะไร? **คำตอบ** idempotence หมายความว่าการดำเนินการสามารถถูกเรียกใช้ได้หลายครั้งโดยไม่เปลี่ยนผลลัพธ์เกินกว่าการเรียกใช้ครั้งแรก ใน Laravel สิ่งนี้ป้องกันผลข้างเคียงที่ไม่พึงประสงค์ระหว่างการ retries job หรือ messages ที่ซ้ำกัน ตัวอย่างเช่น job สร้างคำสั่งซื้อแบบ idempotent จะตรวจสอบว่าคำสั่งซื้อมีอยู่แล้วหรือไม่ก่อนที่จะสร้าง เพื่อหลีกเลี่ยงการซ้ำซ้อนหาก job ถูก retry หลังจาก timeout ใช้ ShouldBeUnique, WithoutOverlapping หรือ deduplicationId เพื่อรับประกัน idempotence ## มีอีก 19 คำถาม - ข้อได้เปรียบหลักของการใช้ event แทนการ dispatch job โดยตรงสำหรับการสื่อสารระหว่าง service คืออะไร? - ควรใช้ ShouldBeEncrypted สำหรับ queued job ในบริบทใด? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Laravel อื่นๆ - [พื้นฐาน PHP](https://sharpskill.dev/th/technologies/laravel/interview-questions/php-basics.md): 25 คำถาม, Junior - [พื้นฐาน OOP ใน PHP](https://sharpskill.dev/th/technologies/laravel/interview-questions/php-oop-essentials.md): 20 คำถาม, Junior - [Composer & Autoloading](https://sharpskill.dev/th/technologies/laravel/interview-questions/composer-autoloading.md): 18 คำถาม, Junior - [พื้นฐาน Laravel](https://sharpskill.dev/th/technologies/laravel/interview-questions/laravel-fundamentals.md): 20 คำถาม, Junior - [Laravel Routing](https://sharpskill.dev/th/technologies/laravel/interview-questions/laravel-routing.md): 20 คำถาม, Junior - [Blade Templates](https://sharpskill.dev/th/technologies/laravel/interview-questions/blade-templates.md): 18 คำถาม, Junior - [Request & Response](https://sharpskill.dev/th/technologies/laravel/interview-questions/request-response.md): 20 คำถาม, Junior - [พื้นฐาน Eloquent ORM](https://sharpskill.dev/th/technologies/laravel/interview-questions/eloquent-orm-basics.md): 22 คำถาม, Junior - [Eloquent Relationships](https://sharpskill.dev/th/technologies/laravel/interview-questions/eloquent-relationships.md): 25 คำถาม, Mid-Level - [Migrations & Schema Builder](https://sharpskill.dev/th/technologies/laravel/interview-questions/database-migrations.md): 20 คำถาม, Mid-Level - [การตรวจสอบและฟอร์ม](https://sharpskill.dev/th/technologies/laravel/interview-questions/validation-forms.md): 22 คำถาม, Mid-Level - [การยืนยันตัวตน](https://sharpskill.dev/th/technologies/laravel/interview-questions/authentication.md): 20 คำถาม, Mid-Level - [การให้สิทธิ์และ Policies](https://sharpskill.dev/th/technologies/laravel/interview-questions/authorization-policies.md): 18 คำถาม, Mid-Level - [API Resources & Authentication](https://sharpskill.dev/th/technologies/laravel/interview-questions/api-resources-authentication.md): 26 คำถาม, Mid-Level - [Middleware](https://sharpskill.dev/th/technologies/laravel/interview-questions/middleware.md): 18 คำถาม, Mid-Level - [Service Container & DI](https://sharpskill.dev/th/technologies/laravel/interview-questions/service-container-di.md): 20 คำถาม, Mid-Level - [Queues & Jobs](https://sharpskill.dev/th/technologies/laravel/interview-questions/queues-jobs.md): 22 คำถาม, Mid-Level - [Events & Listeners](https://sharpskill.dev/th/technologies/laravel/interview-questions/events-listeners.md): 18 คำถาม, Mid-Level - [การแจ้งเตือนและเมล](https://sharpskill.dev/th/technologies/laravel/interview-questions/notifications-mail.md): 20 คำถาม, Mid-Level - [File Storage](https://sharpskill.dev/th/technologies/laravel/interview-questions/file-storage.md): 18 คำถาม, Mid-Level - [Testing & PHPUnit](https://sharpskill.dev/th/technologies/laravel/interview-questions/testing-phpunit.md): 24 คำถาม, Mid-Level - [Caching](https://sharpskill.dev/th/technologies/laravel/interview-questions/caching.md): 18 คำถาม, Mid-Level - [Livewire & Inertia](https://sharpskill.dev/th/technologies/laravel/interview-questions/livewire-inertia.md): 20 คำถาม, Mid-Level - [Eloquent Advanced](https://sharpskill.dev/th/technologies/laravel/interview-questions/eloquent-advanced.md): 24 คำถาม, Senior - [Repository Pattern](https://sharpskill.dev/th/technologies/laravel/interview-questions/repository-pattern.md): 20 คำถาม, Senior - [Laravel Packages](https://sharpskill.dev/th/technologies/laravel/interview-questions/laravel-packages.md): 20 คำถาม, Senior - [Performance Optimization](https://sharpskill.dev/th/technologies/laravel/interview-questions/performance-optimization.md): 22 คำถาม, Senior - [Security Best Practices](https://sharpskill.dev/th/technologies/laravel/interview-questions/security-best-practices.md): 22 คำถาม, Senior - [Laravel Octane](https://sharpskill.dev/th/technologies/laravel/interview-questions/laravel-octane.md): 18 คำถาม, Senior - [Observability & Monitoring](https://sharpskill.dev/th/technologies/laravel/interview-questions/observability-monitoring.md): 20 คำถาม, Senior - [Deployment & DevOps](https://sharpskill.dev/th/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/th/technologies/laravel/interview-questions/laravel-distributed-systems