Q: When to use Parallel vs Async?
✅ Answer:
"Parallel is used for CPU-bound operations where computation is heavy,
whereas async/await is used for I/O-bound operations where the system waits for external resources like APIs or databases."
👉 Bangla:
"CPU heavy কাজ হলে Parallel, আর external wait থাকলে Async/Await ব্যবহার করি।"
| Feature | Parallel | Async/Await |
|---|---|---|
| Type | CPU-bound | I/O-bound |
| Thread | Multiple threads | Non-blocking |
| Performance | Fast for heavy computation | Efficient for waiting |
| Use Case | Data processing | API/DB/File |
Scenario 1: Employee Data Processing (CPU-Bound → Parallel)
Business Requirement
HR system-এ 500,000 employee records আছে।
প্রতিটি employee-এর জন্য:
- Salary calculation
- Tax calculation
- Bonus calculation
করতে হবে।
✅ CPU doing work → Parallel
Examples:
- Salary Calculation
- Report Generation
- Image Processing
- Data Transformation
✅ CPU waiting → Async/Await
Examples:
- API Call
- Database Query
- File Read/Write
- Azure Blob Storage Access
No comments:
Post a Comment