Abstract
Query-as-a-Service (QaaS) platforms like Amazon Athena offer a convenient way to query raw data "in situ," but they often suffer from high latency and costs when dealing with semi-structured formats like CSV. This paper proposes an adaptive middleware that uses serverless functions (FaaS) to automatically transform data—transcoding, chunking, and sorting—based on query patterns and user-defined budgets to find the "sweet spot" between storage costs and query performance.
Introduction
Modern data stacks often face a dilemma: data warehouses are highly optimized but expensive to maintain for infrequent queries, while QaaS systems are cheap to start but inefficient due to a lack of traditional database optimizations. When users query raw CSV or JSON files in QaaS, they pay for every byte scanned. While converting to columnar formats like Apache Parquet is a best practice, doing so for every dataset is not always cost-effective. This research addresses the challenge of adaptive optimization: automatically deciding which data transformations are worth the effort based on specific user budgets and query histories.
System Architecture
The proposed system architecture consists of two primary components: a Controller and a Transformer.
- The Controller: Acts as a middleware that monitors incoming queries, analyzes table metadata (size, types), and considers a user-provided monetary budget to decide which transformations yield the best ROI.
- The Transformer: Utilizes Function-as-a-Service (FaaS), specifically AWS Lambda, to execute transformations. FaaS is ideal for this task as it scales to zero and provides fine-grained billing for bursty workloads.
The system explores three primary transformations: transcoding (CSV to Parquet), chunking (adjusting file counts), and sorting (reordering data for better skipping).
Experimental Evaluation
The approach was evaluated using the TPC-H SF-100 benchmark (100GB of raw data), focusing on the largest tables: lineitem, orders, and partsupp.
Key Results
- Massive Savings: Converting TPC-H data from CSV to Parquet reduced runtime by over 3x and slashed costs from approximately $9.00 to $0.76 on Athena.
- Lambda Efficiency: Using FaaS for chunking was significantly cheaper than transcoding from scratch because it processed less data.
- Adaptive ROI: Sorting specific columns (e.g.,
l_shipdate) led to a 43% improvement in both cost and latency for relevant queries due to enhanced data skipping.
Key Insights
A critical finding was the "U-shape" of partitioning performance. As shown in the figure below, there is a "Goldilocks zone" for file counts.
In Athena tests, 100 partitions per table was the optimal point. Having too few files (e.g., 20) limited parallelism, making it slower than raw CSV, while too many files (e.g., 900) introduced excessive metadata overhead. Other insights include:
- Selective Transcoding: Converting only the largest table (
lineitem) reduced costs by 4x. - Setup Tax: For small tables, the fixed cost of invoking serverless functions can exceed the savings, requiring the controller to skip optimizations for tiny datasets.
Discussion and Future Work
While effective, the system faces limitations. Keeping multiple transformed copies increases storage costs, necessitating automated cleanup based on economic models like the "five-minute rule." Additionally, because QaaS platforms are proprietary "black boxes," optimizations rely on empirical observations rather than internal metrics. Future work will explore complex transformations like materialized views and address cloud jitter to provide more consistent latency guarantees.
Summary updated