π’ Day 16/30 - SQL, PYTHON, ETL, DATA MODELING CHALLENGE Solutions
Solutions for March 17th, 2025 CHALLENGE β unlock solutions + reasoning!
π Hey Data Engineers!
Welcome to Day 16 of the 30-Day Data Engineering Challenge π.
Todayβs Challenge covers:
π SQL: Recursive CTEs for Hierarchical Data
πΉ Learn how to retrieve all employees reporting to a manager, including indirect reports using recursive queries.
π Python: Multi-threading & Performance
πΉ Understand when to use threading vs. multiprocessing for executing concurrent tasks efficiently.
β‘ ETL: Handling Failures in Data Pipelines
πΉ Discover best practices for retrying failed ETL jobs due to intermittent network issues.
π Data Modeling: Normalization vs. Denormalization
πΉ Learn when to denormalize a schema for analytical workloads vs. when to normalize for transactional integrity.
Want deep dives + runnable code? Upgrade to the Annual Plan and master these concepts like a pro!
π§ Understand, Don't Memorize:
β
Clear explanations & reasoning
β
Why this solution works
β
Key optimizations & best practices
π‘ Want deep dives + runnable code? Upgrade to the Annual Plan and master these concepts like a pro!
π SQL Challenge - Recursive Queries
π Question:
Which SQL query correctly retrieves all employees reporting to a given manager, including indirect reports?
π A) SELECT * FROM employees WHERE manager_id = 5;
π B) WITH RECURSIVE emp_cte AS (...) SELECT * FROM emp_cte;
π C) SELECT * FROM employees INNER JOIN managers ON employees.id = managers.id;
π D) SELECT * FROM employees WHERE id = ANY(SELECT manager_id FROM employees);
β Answer: B) WITH RECURSIVE emp_cte AS (...) SELECT * FROM emp_cte;
π Explanation:
Recursive CTEs (
WITH RECURSIVE) allow us to traverse hierarchical relationships such as employee-manager structures.This approach recursively selects direct and indirect reports, making it ideal for organizational trees, category hierarchies, and dependency chains.
π‘ Best Practices:
β Always use recursive queries when dealing with hierarchical data.
β Include a termination condition in recursive CTEs to prevent infinite loops.
β Use depth limits if necessary to control recursion depth.
π Python Challenge - Multi-threading
π Question:
Which Python function is best for executing multiple tasks concurrently using threading?
π A) threading.Thread(target=function).start()
π B) multiprocessing.Process(target=function).start()
π C) asyncio.run(function())
π D) os.fork()
β Answer: A) threading.Thread(target=function).start()
π Explanation:
Threading allows multiple tasks to run concurrently in the same memory space, making it ideal for I/O-bound tasks like network requests or file reading.
multiprocessingcreates separate processes, better suited for CPU-bound tasks.asynciois for asynchronous programming, which is different from multithreading.os.fork()is for low-level process management, not general-purpose threading.
π‘ Best Practices:
β Use threading for I/O-bound tasks (e.g., API calls, file reading).
β Use multiprocessing for CPU-intensive tasks (e.g., data processing, ML).
β Avoid global variables in threaded programs to prevent race conditions.
β‘ ETL Challenge - Handling Failures
π Question:
What is the best way to handle an ETL job that fails due to an intermittent network issue?
π A) Retry the job with exponential backoff
π B) Ignore the failure and proceed to the next step
π C) Stop the pipeline and notify the user
π D) Delete and reload all data
β Answer: A) Retry the job with exponential backoff
π Explanation:
Exponential backoff gradually increases the wait time between retries, reducing network congestion and improving reliability.
Ignoring the failure (B) can lead to data inconsistencies.
Stopping the pipeline (C) without retrying isn't ideal unless the failure is persistent.
Deleting and reloading all data (D) is inefficient and unnecessary for transient issues.
π‘ Best Practices:
β Implement retry logic with increasing delays (e.g., 1s, 2s, 4s, 8s).
β Use logging and monitoring to track failures and retries.
β Store intermediate checkpoints to avoid reprocessing large datasets.
π Data Modeling Challenge - Normalization vs. Denormalization
π Question:
Which scenario is best suited for a fully denormalized schema?
π A) Analytical reporting with frequent aggregations
π B) Transactional systems requiring strict data integrity
π C) Highly normalized OLTP databases
π D) Large-scale e-commerce platforms processing orders
β Answer: A) Analytical reporting with frequent aggregations
π Explanation:
Denormalization speeds up read performance by reducing joins, making it ideal for analytical workloads (OLAP systems, dashboards, data warehouses).
Transactional systems (OLTP) need normalization to ensure data integrity and avoid redundancy.
E-commerce platforms (D) often balance both approaches depending on performance needs.
π‘ Best Practices:
β Normalize OLTP databases (3NF) to prevent redundancy.
β Denormalize OLAP databases for faster reads.
β Use materialized views or caching instead of full denormalization when possible.
π Want the Full DEEP DIVE Analysis?
π Concept breakdowns, live runnable code, and expert strategies are available for paid members.
π₯ Upgrade to Annual Membership for:
β
Advanced SQL & Python solutions
β
Real-world ETL & Data Modeling case studies
β
FAANG-level interview strategies



Something is mismatched in the LinkedIn questions and answers here? Or I am checking incorrect post?
https://www.linkedin.com/posts/activity-7307408152839213059-Sp8g?utm_source=share&utm_medium=member_desktop&rcm=ACoAAAqUxM0Bvth5IJDYhIt8cGJL_sBLmWF0xXg