LLM-Assisted Backend Development: Dual-Model Collaboration and Cost Evaluation
This article documents a weekend practice of optimizing a backend management system using LLM-assisted coding. Over 8 to 10 hours, a dual-model approach was employed for a focused optimization round. Aimed at developers seeking cost-effective backend maintenance, the article covers task decomposition, dual-model division of labor, and statistical results on costs, tool calls, and model differences. Note that the figures are based on this specific practice and should be recalculated for other projects.
This article records a weekend practice of backend system optimization. Working on a semi-finished backend management system, a developer spent approximately 8 to 10 hours completing a round of concentrated optimization using AI coding tools. Targeted at developers looking for low-cost backend maintenance, it introduces task decomposition methods, a dual-model division of labor, and statistical results regarding costs, tool calls, and model differences. All figures are from this specific practice; apply them to your own projects with caution.
1. Breaking Down Vague Requirements into Executable Tasks
Many users tend to give LLMs broad requests, expecting a complete result in one go. In projects with large existing codebases like backend systems, this approach easily leads to context overflow and causes the model to lose focus. In this practice, the opposite approach was taken: instructions were given for only one file or one feature point at a time, clearly specifying three things—what to implement, the expected effect, and what should not be changed.
A reusable task description can follow this structure:
- Target File: List the file paths allowed to be modified this time.
- Feature Point: Describe the behavior to be added or modified in one sentence.
- Expected Effect: Describe the result that should appear upon completion, such as API return values or UI behavior.
- Boundary Conditions: Explain how to handle empty data, duplicate submissions, or insufficient permissions.
- No-Go Items: List the APIs, table structures, or public modules that cannot be touched.
- Acceptance Criteria: Provide executable or checkable criteria for validation.
This approach forces the model to work within a smaller context, reducing the risk of unrelated code being altered. In practice, the more specific the task description, the less rework is required.
2. Dual-Model Collaboration: Separating Execution and Review
Two models were used in this development session, each assuming a different role. Model A is the primary executor, with a lower unit price and direct instruction execution, responsible for code generation and initial modifications. Model B is responsible for review; it performs more stably in defensive programming, has a relatively higher unit price, and is mainly used for critical logic and review phases.
This division of labor has two benefits. First, the execution layer handles a large amount of mechanical coding and file modifications, advancing more tasks per unit time. Second, the review layer cross-checks the execution layer’s output, catching issues earlier. The original records did not fully log the versions and task counts of the two models, so conclusions like “how many defects cross-checking reduced” cannot be precisely quantified and remain observational findings from this practice.
3. Cost and Caching: How to Interpret the Numbers
This interaction involved approximately 820 messages, consuming around 660,000 tokens in total, with an overall cost of about 10 RMB (around $1.40 USD). Among these, cache hits accounted for about 659,900 tokens. Calculated as 659,900 divided by 660,000, the cache hit rate is approximately 99.98%. Both numbers are rounded. The original records did not specify the statistical source, so it is recommended to cross-verify against the platform’s usage billing.
The high cache hit rate is because most of the context in long conversations is repetitive. During development, the model repeatedly reads system structure descriptions, existing code files, and API definitions. Once cached, these contents do not need to be fully recalculated each time, significantly reducing unit costs.
When reading these numbers, note the following:
- Whether the cost includes extra requests generated by retries and tool calls is not broken down in this record.
- Cache pricing rules vary by platform; 10 RMB is the result under this specific statistical scope and cannot be directly generalized to other projects.
- Once the context structure changes, the cache hit rate usually drops, so a high hit rate should not be treated as a fixed metric.
4. Agent Tool Calling: A Complete Development Loop
By message count, assistant messages accounted for about 50%, tool messages for about 42.3%, and other messages for about 7.7%. Tool calls account for nearly half, indicating that the model did not just output text but participated in actual engineering operations.
A typical round of work generally followed this sequence:
- Read: Call read tools to understand the existing directory structure and core logic.
- Modify: Edit the target file based on the task description.
- Analyze: Locate potential issues, such as null pointers or unvalidated input parameters.
- Verify: Confirm whether the modification works through syntax checks or simulated runs.
- Rollback or Fix: If verification fails, undo the changes or enter the next round of modification.
Common failure modes include: the tool reading the wrong file, failing to re-verify after modifications, and missing previously agreed boundary conditions when the context is too long.
The original records did not track the number of manual rollbacks, so it is impossible to quantify how much manual intervention was reduced. To evaluate this, it is recommended to track three metrics: manual rollback count, review rounds, and failed tool call rate.
5. Model Capability Comparison: Execution vs. Defensive Programming
Model A’s advantages lie in its low cost and fast execution. It can accurately understand instructions and is suitable for batch coding. However, it occasionally misses defensive handling, such as failing to check for null pointers or validate input parameters. When encountering such issues, you usually need to explicitly point them out in the conversation and request a fix.
Model B performs more stably in defensive programming. In this task set, it rarely missed null value handling or input validation. This conclusion has limited scope: the task set was small, defects were identified based on manual review, and no systematic defect classification statistics were performed. Its calling cost is higher, making it more suitable for critical logic and review phases.
Model Selection Checklist
- Cost: Whether the unit price per thousand tokens and cache pricing fit the budget.
- Execution Capability: Whether it can modify only the specified files without unauthorized expansion of the modification scope.
- Defensive Programming: Whether it can proactively handle null values, exceptions, and boundary conditions.
- Review Cost: Whether the time and cost of a single review are acceptable.
- Applicable Tasks: Batch rewriting is suitable for the execution layer; logic involving permissions, payments, and data consistency is suitable for review by the review layer.
6. FAQ
How to choose for multi-model collaboration?
First, layer tasks by risk. Assign low-risk repetitive modifications to the execution layer, and high-risk logic to the review layer, with manual confirmation before merging. When two models have different training backgrounds, cross-checking is more likely to expose single-model blind spots, but this needs to be validated with your own actual tasks.
What to note?
- Give only one task with a clear scope at a time to avoid presenting too many objectives at once.
- Clearly state the no-go items in the instructions; otherwise, the model might casually modify public modules.
- The output of the execution layer must be verified and cannot be merged directly.
What are common mistakes?
- Treating the cost of a single conversation as the overall cost, ignoring the extra overhead of retries and reviews.
- Treating the cache rate as a fixed metric, ignoring that the hit rate drops after context changes.
- Skipping manual review just because the review model is more stable.
Conclusion
Based on this practice, several conclusions can be drawn. The more specifically tasks are decomposed, the easier it is for the model to complete the work within restricted boundaries. The dual-model division of labor can disperse the pressure of execution and review, but this conclusion only applies to the task scale and codebase size of this practice. The caching mechanism indeed reduces the cost of long conversations, and the specific savings depend on platform pricing and context structure. Readers are advised to run small-scale tasks first, record their own cost and defect data, and then decide whether to expand the scope of use.
