Apple Interview Questions
Monkey patching is dynamically modifying or extending a class or module at runtime — without changing the original source code. In data engineering : us...
Explain Monkey Patching with an example.
Monkey patching is dynamically modifying or extending a class or module at runtime — without changing the original source code. In data engineering : used in unit tests to mock external dependencies (database connections, API calls, S3 reads) without modifying production code. Risks : makes code harder to trace, breaks encapsulation, can cause subtle bugs if the patched behavior differs from production. Use unittest.mock.patch (Python's built in) instead of raw monkey patching when possible — it
Compare Redshift vs PostgreSQL.
Redshift PostgreSQL Purpose OLAP — analytics, BI OLTP — transactional workloads Storage Columnar (per column compression) Row oriented Scale Petabyte scale, distributed cluster Single node (or limited sharding) Joins Optimized for large fact dimension joins Optimized for small, frequent row lookups DML Batch INSERT/COPY (no high frequency updates) Full ACID, row level locks Query speed Fast for aggregate queries on millions of rows Fast for primary key lookups, small queries Use Redshift : analy
Explain Parquet vs CSV data formats.
Parquet CSV Storage Columnar Row based Compression Per column (Snappy/ZSTD), 5 10x smaller None or gzip on full file Schema Embedded in file Inferred or external Query speed Column pruning + predicate pushdown Full file scan Splittable Yes Only with careful partitioning Human readable No Yes Use Parquet : data lakes (S3/ADLS), Spark/Presto/Athena analytical workloads — especially wide tables where you only query a few columns. Use CSV : small datasets, data exchange with external systems, when h
Contrast Spark and MapReduce processing models.
Spark MapReduce Processing In memory (RDD caching) Disk based (writes after each stage) Speed 10 100x faster for iterative workloads Slow — disk I/O dominates APIs DataFrame, SQL, Streaming, ML, GraphX Low level Map + Reduce Fault tolerance RDD lineage — recompute lost partitions Recompute from HDFS checkpoint Streaming Spark Structured Streaming (micro batch) Not native Memory Higher RAM requirements Lower RAM (spills to disk) Key insight : MapReduce writes intermediate results to HDFS between
Write Python code for binary tree traversal.
Optimize median-finding for large lists algorithmically.
Naive approach : sort the list → O(n log n), not scalable for streaming. Optimal approach: two heap method — maintain a max heap (lower half) and min heap (upper half): Complexity : O(log n) per insert, O(1) median query. For very large datasets : use reservoir sampling + order statistics, or quantile sketches (T Digest, QDigest) for approximate medians with bounded memory.
Solve a mock "market basket analysis" schema design.
Market basket analysis finds products frequently bought together (association rules). Schema : Finding frequently co purchased pairs : For large scale analysis: use PySpark MLlib's FPGrowth algorithm.
Design an end-to-end data pipeline for analytics.
Ingestion : Batch: Airflow → JDBC extract → S3/ADLS (Bronze layer) Streaming: Kafka → Spark Streaming → Bronze Delta Transform (Silver) : Dedup, type cast, null handling Join with reference/dimension data Schema validation (Great Expectations) Aggregate (Gold) : Pre compute KPIs, daily aggregates, feature tables Orchestrated by Airflow DAGs Serve : BI: Redshift/Snowflake/BigQuery → Tableau/Looker ML features: Feature Store (Redis/Feast) APIs: FastAPI reading from Gold tables Observability : row