Senior Go interview में केवल यह पूछना पर्याप्त नहीं है कि Goroutine कैसे बनाते हैं या interface क्या होता है। असली परीक्षा तब होती है जब production API में memory लगातार बढ़ रही हो, Goroutines अटक रही हों, database saturation हो रहा हो या distributed service में duplicate requests आ रही हों।
Senior और Lead Engineers से interviewer यह अपेक्षा करता है कि वे सिर्फ working code नहीं, बल्कि failure handling, performance trade-offs, observability और maintainability भी समझाएँ। नीचे दिए गए 15 सवालों में core Go, concurrency, memory management और system architecture शामिल हैं।
Key Takeaways: Interview में किस पर ध्यान दें?
- Concurrency: Goroutines, Channels, Mutex और Race Conditions।
- Performance: GC, profiling, memory allocations और benchmarks।
- Reliability: Context cancellation, timeouts और graceful shutdown।
- Architecture: Microservices, caching, database consistency और observability।
Core Golang के 5 जरूरी Interview Questions कौन-से हैं?
1. Goroutines और OS Threads में क्या अंतर है?
Answer: Goroutines Go runtime द्वारा schedule की जाने वाली lightweight concurrent tasks हैं। OS Threads को operating system manage करता है। कई Goroutines उपलब्ध OS Threads पर execute हो सकती हैं। इससे concurrency आसान होती है, लेकिन unlimited Goroutines बनाना सुरक्षित नहीं है।
2. Go में Interface और Composition क्यों महत्वपूर्ण हैं?
Answer: Go interfaces implicit रूप से satisfy होते हैं। इससे implementation को concrete type से tightly couple किए बिना dependencies inject की जा सकती हैं। Composition के जरिए छोटे components जोड़कर maintainable architecture बनाया जा सकता है।
3. Slice और Array में क्या अंतर है?
Answer: Array की length उसके type का हिस्सा होती है। Slice एक descriptor है जिसमें underlying array का reference, length और capacity होती है। Slice को append करने पर नया underlying array बन सकता है, इसलिए shared backing array के side effects समझना जरूरी है।
4. Go में Memory Leak कैसे हो सकता है?
Answer: GC unreachable objects reclaim करता है, लेकिन global maps, unbounded caches या blocked Goroutines के references में objects जीवित रह सकते हैं। Heap और Goroutine profiles से retention की जाँच करें।
5. Defer, Panic और Recover का सही उपयोग क्या है?
Answer: defer cleanup operations के लिए उपयोगी है। panic असामान्य स्थितियों में control flow रोकता है और recover केवल deferred function में panic को पकड़ सकता है। सामान्य business errors के लिए explicit error handling बेहतर है।
Concurrency और Coding के 5 सवाल कैसे हल करें?
6. Goroutine Leak को कैसे रोकेंगे?
Answer: हर blocking operation के लिए exit condition रखें। context.Context, channel closure और cancellation का उपयोग करें। Goroutine count को monitor करें और pprof से blocked stacks inspect करें।
7. Mutex और Channel में से क्या चुनेंगे?
Answer: Shared state को protect करने के लिए sync.Mutex सरल और प्रभावी है। Channels task distribution और Goroutines के बीच communication के लिए उपयोगी हैं। चुनाव code clarity और synchronization requirements के आधार पर करें।
8. Data Race क्या है और इसे कैसे पकड़ेंगे?
Answer: जब multiple Goroutines बिना उचित synchronization के एक ही memory location access करती हैं और कम-से-कम एक write होता है, तो data race हो सकती है। go test -race ./... से संभावित races की पहचान करें।
9. Bounded Worker Pool कैसे बनाएँगे?
Answer: Fixed workers और bounded jobs channel से concurrency सीमित करें। इससे CPU-heavy tasks की संख्या नियंत्रित होती है और unbounded task creation से बचाव होता है।
func worker(jobs <-chan int, results chan<- int) {
for job := range jobs {
// Process one task
results <- job * 2
}
}
10. Context का उपयोग कब करेंगे?
Answer: Request-scoped deadlines, cancellation और metadata के लिए context.Context इस्तेमाल करें। इसे function calls में स्पष्ट रूप से pass करें और long-running tasks को cancellation signal का सम्मान करना सिखाएँ।
Senior Backend Architecture के 5 कठिन सवाल कौन-से हैं?
11. High-Traffic API की Latency कैसे कम करेंगे?
Answer: पहले p95 और p99 latency, CPU profiles, heap allocations और database query timings मापें। फिर caching, query optimization, connection pooling या concurrency tuning में से वास्तविक bottleneck के अनुसार बदलाव करें।
12. Microservices में Duplicate Requests कैसे रोकेंगे?
Answer: Payment जैसे operations में idempotency keys, unique database constraints और transactional state transitions उपयोग करें। केवल retry बंद करना पर्याप्त नहीं है, क्योंकि network failure के बाद client को operation का परिणाम पता नहीं हो सकता।
13. Graceful Shutdown कैसे implement करेंगे?
Answer: Signal मिलने पर नए requests स्वीकार करना बंद करें, in-flight requests को सीमित समय तक पूरा होने दें और workers तथा database connections को व्यवस्थित तरीके से बंद करें। Shutdown deadline के बाद forced termination की policy रखें।
14. Cache Invalidation और Data Consistency कैसे संभालेंगे?
Answer: TTL, explicit invalidation और versioning जैसे patterns पर विचार करें। Distributed systems में cache और database के बीच consistency की सीमाएँ स्पष्ट करें। Critical updates के लिए transactional writes और event-driven invalidation उपयुक्त हो सकते हैं।
15. Monolith को Go Microservices में कब बदलेंगे?
Answer: जब अलग domains की scaling, deployment या reliability requirements स्पष्ट रूप से अलग हों, तब extraction उपयोगी हो सकती है। पहले modular boundaries बनाएँ, एक सीमित service निकालें और latency, deployment frequency तथा operational cost मापें। केवल trend के कारण migration न करें।
Interview में Go की तुलना दूसरी Languages से कैसे समझाएँ?
| Factor | Go | Java | Node.js | Python |
|---|---|---|---|---|
| Concurrency | Goroutines और Channels | Threads और concurrency APIs | Event loop और async I/O | asyncio, threads और processes |
| Memory Management | Garbage Collector | JVM Garbage Collector | V8 Garbage Collector | Reference counting और cyclic GC |
| Deployment | अक्सर standalone binary | JVM/runtime आवश्यक | Node.js runtime आवश्यक | Interpreter सामान्यतः आवश्यक |
| मुख्य Focus | Concurrent services और tooling | Enterprise applications | Async I/O applications | Automation और data ecosystem |
इनमें से कोई language हर workload में सबसे तेज नहीं है। Senior interview में benchmark का दावा करने के बजाय workload, runtime configuration और measurable trade-offs समझाना ज्यादा प्रभावी है।
Lead Engineer के रूप में बेहतर उत्तर कैसे दें?
हर सवाल का उत्तर तीन हिस्सों में दें: Concept, Trade-off और Production Example. उदाहरण के लिए, Worker Pool समझाते समय केवल Goroutines की syntax न बताएँ; यह भी समझाएँ कि bounded queue overload कैसे नियंत्रित करती है, cancellation कैसे काम करती है और metrics से capacity कैसे तय होगी।
Final Verdict: Senior Go interview में syntax आपकी शुरुआत है, लेकिन concurrency safety, profiling, failure handling और system design आपकी वास्तविक engineering maturity दिखाते हैं। इन 15 सवालों की तैयारी करते समय छोटे code examples लिखें, race detector चलाएँ और अपने architectural decisions के पीछे स्पष्ट कारण समझाने का अभ्यास करें।
Senior और Lead Golang Engineers के लिए केवल coding और concurrency समझना काफी नहीं है। Production में लाखों concurrent requests handle करने, API rate limiting और scalable backend architecture design करने की समझ भी जरूरी है। इसके लिए हमारी detailed guide पढ़ें: Go में 1 Million Concurrent Requests कैसे Handle करें? API Rate Limiting और Scaling की Production Strategy .
Post a Comment
Blogger FacebookYour Comment Will be Show after Approval , Thanks