Search Ads Expansion and LLM Inference Cost Reduction: A Practical Guide for Developers

    A practical guide covering two topics developers often face together: how to evaluate and scale search ad campaigns after ad placement expansion in app stores, and how to reduce LLM inference costs through quantization, operator fusion, PagedAttention, disaggregated inference, and elastic scaling—each with its适用 conditions, trade-offs, and rollback strategies spelled out. Wait—each with applicable conditions, trade-offs, and rollback strategies spelled out.

    Search Ads Expansion and LLM Inference Cost Reduction: A Practical Guide for Developers

    Part 1: What Developers Should Check After Search Ad Placement Expansion

    App store documentation notes that search remains one of the primary ways users discover apps. Platforms plan to add more ad placements in search results, moving beyond the single top promotion slot.

    Existing search ad campaigns are automatically eligible for the new placements—no code or configuration changes required. Advertisers cannot bid on individual placements; the platform handles bidding centrally. This lowers integration costs, but it also means performance across old and new placements gets mixed together. Looking only at total installs makes it hard to tell where incremental growth comes from.

    1. Understand Billing Models and Metrics First

    • CPT (Cost Per Tap): You pay each time a user taps the ad. It reflects click intent, but a tap is not an install.
    • CPI (Cost Per Install): You pay per valid install, which is closer to actual conversion.
    • CPM (Cost Per Mille): You pay per thousand impressions. Since it ignores whether users tap or install, it is not suitable for measuring conversion directly.

    When evaluating ad performance, rely primarily on CPI plus downstream retention and monetization data; treat CPT as a supplementary reference only.

    2. Build Working Attribution and Event Tracking

    Complete at least these four tasks:

    • Unify the attribution window: Define how long after a tap an install is credited to the ad—for example, 7 days—and use this same window across all reports.
    • Track data by search term: Associate each install with its specific search term. If platform reports cannot distinguish ad placements, use time-period comparisons or split experiments instead of placement-level analysis.
    • Detect abnormal traffic: Watch for sudden click spikes paired with installs that show no retention. Set anomaly thresholds and blacklist suspicious sources.
    • Manage privacy risk: Systems like iOS require user authorization for tracking, so attribution data can only be collected within the scope of user consent. Never put personally identifiable information such as phone numbers or email addresses into link parameters.

    3. Use Controlled Experiments Before Increasing Budget

    Raising budgets directly is an easy way to waste money. A safer approach:

    1. Select a group of high-value search terms and keep another group unchanged as a control.
    2. Observe long enough for the sample size to support conclusions. Two weeks is a common starting point; the exact duration depends on daily install volume.
    3. Compare CPI, next-day retention, and payment conversion rates between the two groups.
    4. Check whether organic installs declined. If paid installs are merely replacing organic ones, actual increment is smaller than the reported numbers suggest.
    5. Increase budget gradually only when CPI is below your target threshold and retention has not dropped.

    Deep links skip splash screens and take users directly to target content inside an app. The key is handling two cases: users who have the app installed and those who do not.

    1. def handle_deep_link(click):
    2. target = click.get("deep_link")
    3. # Validate the link format to avoid redirecting to illegal addresses
    4. if not is_valid_deep_link(target):
    5. return redirect_to_default_page()
    6. if is_app_installed(click["device_id"]):
    7. open_app(target)
    8. else:
    9. # For users without the app, redirect to a custom product page
    10. # while preserving the target page info, so they still land
    11. # on the original content after installation
    12. redirect_to_app_store(
    13. custom_product_page=click["product_page"],
    14. deferred_deep_link=target,
    15. )

    Additional points to handle in production:

    • Domain association: iOS Universal Links and Android App Links require association files on your server. If the configuration is missing, links fall back to opening in the browser, and conversion rates drop noticeably.
    • Deferred deep links: After a user without the app completes installation, the app must read the deferred deep link data to navigate to the original content page.
    • Denied permissions: Some devices reject tracking or notification permissions. The app should have a default landing page so users never see a blank screen.

    Part 3: Why LLM Inference Costs Are High

    High inference costs stem mainly from two sources: the memory-access characteristics of autoregressive generation, and the GPU memory consumed by the KV Cache.

    1. Autoregressive Generation Is Memory-Bandwidth Bound

    During training, models process large batches in parallel with high matrix multiplication utilization. During inference, the model generates tokens one at a time, and each token requires reading the full model weights. A single request involves little computation, so GPU compute units often sit idle waiting on memory data.

    Increasing batch size amortizes the cost of weight reads, so the key to serving efficiency is keeping the GPU busy with enough concurrent requests.

    2. KV Cache Memory Footprint

    To avoid recomputation, inference caches the key-value pairs of past tokens—the KV Cache. Its memory usage can be estimated as:

    1. KV Cache memory ≈ 2 × layers × KV heads × head dim × sequence length × batch size × bytes per element

    For a model with 32 layers, 8 KV heads, head dimension 128, and FP16 (2 bytes per element):

    • Single request, sequence length 4096: KV Cache ≈ 512 MiB.
    • Same length with batch size 32: KV Cache ≈ 16 GiB.

    The KV Cache therefore grows roughly linearly with sequence length and batch size—not exponentially. Paging and memory fragmentation reduce effective memory utilization but do not change the overall growth trend.

    Before optimizing, estimate how much memory the weights and KV Cache each consume, then decide which to tackle first.

    Part 4: Cost-Reduction Options: Conditions, Trade-offs, and Rollback

    1. Quantization

    • When to use: Weights dominate memory usage, latency matters, and the model tolerates small precision loss.
    • Benefit: INT8 weights are roughly half the size of FP16; INT4 roughly one quarter. These figures apply to weights only, excluding KV Cache and activations.
    • Risk: Accuracy may drop. Math reasoning, code generation, and long-context tasks are typically more sensitive than general Q&A.
    • Checklist: Compare accuracy, refusal rate, and output length on your own evaluation set. Start with a 5% traffic canary and set up a rollback switch. If metrics degrade beyond business-defined thresholds, switch back to FP16 immediately.

    2. Operator Fusion

    • When to use: The model contains many small operators with frequent intermediate reads and writes to GPU memory.
    • Benefit: Reduces intermediate writes to memory, lowering per-request latency.
    • Risk: Higher compilation and debugging costs. After framework upgrades, fused operators may break or change behavior.
    • Checklist: Compare single-operator and end-to-end latency, verify outputs match the unfused version, and pin the framework version.

    3. PagedAttention

    • When to use: Services with high variance in request lengths and high concurrency.
    • Benefit: Allocates KV Cache in fixed-size blocks, reducing waste from reserving space for the longest sequence, so the same memory fits more concurrent requests.
    • Risk: Block management adds overhead. If requests are uniformly short, gains are limited.
    • Checklist: GPU memory utilization, achievable batch size, throughput, and P99 latency.

    4. Disaggregated Inference

    The prefill stage processes input prompts and is compute-intensive; the decode stage generates output token by token and is memory-bandwidth intensive. Splitting the two onto separate clusters lets each use hardware better matched to its workload.

    • When to use: Prompts are long, and you have requirements for both time-to-first-token and generation speed.
    • Risk: KV Cache generated by prefill nodes must be transferred across nodes, which depends on high-speed networking. For short-request workloads, transfer overhead may exceed the benefit.
    • Checklist: Measure the share of KV transfer time in end-to-end latency, and compare against a co-located deployment.

    5. Elastic Scaling

    Teams can deploy inference services on a cloud provider’s container platform, store weight files in object storage, and keep versioned releases for easy rollback. When choosing a platform, compare pricing, availability zones, network bandwidth, and operational cost.

    CPU or memory utilization are weak signals for inference services. Better metrics are request queue length, GPU utilization, and P99 latency. The following example scales on queue length and requires a custom metrics adapter:

    1. apiVersion: autoscaling/v2
    2. kind: HorizontalPodAutoscaler
    3. metadata:
    4. name: llm-inference-scaler
    5. spec:
    6. scaleTargetRef:
    7. apiVersion: apps/v1
    8. kind: Deployment
    9. name: llm-deployment
    10. minReplicas: 3
    11. maxReplicas: 50
    12. metrics:
    13. - type: Pods
    14. pods:
    15. metric:
    16. name: inference_queue_length
    17. target:
    18. type: AverageValue
    19. averageValue