Article · 2020-11-27

System Design Practice with Geographic Protection Zones and Multi-Factor Ranking

Problem Modeling

Before designing a solution, we need to formalize and analyze the problem systematically. Once we introduce the concept of node protection radius, the node ranking problem becomes a multi-factor decision problem. We can abstract the main factors influencing ranking as follows:

Combining these factors, we establish a composite scoring model. The composite score for each candidate node can be expressed as a weighted sum of multiple sub-scores:

$$ \text{Score}(\text{node}) = w_1 \times f_{\text{distance}}(\text{node}) + w_2 \times f_{\text{radius}}(\text{node}) \

where $f_{\text{distance}}$ is a distance-based score function, $f_{\text{radius}}$ represents the value produced by whether the node's protection radius is hit, $f_{\text{preference}}$ denotes the score from user preference, $f_{\text{manual}}$ is the operator-configured score, and $w_1, w_2, w_3, w_4$ are corresponding weight coefficients (configurable and adjustable based on business needs).

The introduction of node protection radius creates several scenarios requiring careful handling:

Through this scenario analysis, we clarify which cases the ranking logic must handle and the relative importance of each factor. This foundation supports the design solution that follows.

Design Solution

To address the problem model above, we designed a layered solution. The overall workflow can be summarized as "filter candidate nodes → calculate multi-factor scores → composite score ranking → output ranking results," with emphasis on the calculation and merging strategy of multi-factor scores. Here we explain each step:

This design solution emphasizes flexibility and configurability. Bonus values, weights, and specific scoring functions for each factor are not hardcoded but managed through a configuration center. Operators can adjust priority parameters for node categories or modify the radius bonus magnitude, and the system automatically applies new rules after loading the latest configuration. This design ensures rapid strategy adjustments without code changes. We also reserve interfaces to support future addition of new factors (for example, real-time node load or user ratings).

Implementation Details

We implemented the core logic using Python. The following simplified code examples demonstrate key functional implementations.

First, consider geographic distance calculation and protection radius determination. Given user location (latitude-longitude) and node location plus its protection radius, we need to determine whether the user falls within the node's protection range. This typically requires calculating distance between two coordinate points. For simplicity, we use Euclidean distance approximation (production environments can use more precise spherical distance formulas):

import math

def calc_distance(loc1, loc2):
    """计算两个二维坐标点之间的距离"""
    x1, y1 = loc1
    x2, y2 = loc2
    return math.hypot(x2 - x1, y2 - y1)

# 示例:判断用户是否在节点的保护半径范围内
user_location = (121.4737, 31.2303)  # 用户当前位置 (经度, 纬度),例如某城市坐标
node_location = (121.4600, 31.2200)  # 某节点的位置坐标
protection_radius = 0.5  # 节点保护半径,单位与坐标的单位相同,这里假定为0.5(仅作示例)

distance = calc_distance(user_location, node_location)
in_radius = distance <= protection_radius
print(f"用户与节点距离: {distance:.4f},是否在保护半径内: {in_radius}")

In this example, we defined a simple Euclidean distance calculation function calc_distance and checked whether the distance between user and node is less than the node's protection_radius. At runtime, we perform similar calculations for all candidate nodes and add a boolean attribute such as node.in_protection_radius to mark this result.

Next, we demonstrate how to perform comprehensive scoring and ranking of candidate nodes. We construct a simple node list where each node contains necessary attributes, then calculate scores and rank according to the rules described:

# 定义一些全局参数(在真实系统中这些可能来自配置)
MAX_DISTANCE = 5000.0    # 支持的最大服务距离(米)
RADIUS_BONUS = 20.0      # 命中保护半径奖励分
PREFERENCE_BONUS = 15.0  # 用户历史偏好奖励分

# 模拟候选节点列表,每个节点是一个字典包含相关属性
candidate_nodes = [
    {"node_id": 1, "geo_distance": 1200.0, "in_radius": True,  "category_priority": 0,  "is_user_preferred": False, "manual_weight": 0},
    {"node_id": 2, "geo_distance": 3000.0, "in_radius": False, "category_priority": 5,  "is_user_preferred": True,  "manual_weight": 0},
    {"node_id": 3, "geo_distance": 2500.0, "in_radius": False, "category_priority": 0,  "is_user_preferred": False, "manual_weight": 10},
]

# 计算综合得分
for node in candidate_nodes:
    # 距离分:0距离=100分,最远距离=0分,线性插值
    dist_score = max(0.0, (MAX_DISTANCE - node["geo_distance"]) / MAX_DISTANCE * 100)
    score = dist_score
    if node["in_radius"]:
        score += RADIUS_BONUS
    score += node["category_priority"]
    if node["is_user_preferred"]:
        score += PREFERENCE_BONUS
    score += node["manual_weight"]
    node["score"] = score

# 按score从高到低排序
sorted_nodes = sorted(candidate_nodes, key=lambda n: n["score"], reverse=True)
for n in sorted_nodes:
    print(f"节点{n['node_id']} 综合得分: {n['score']:.1f}")

The code above illustrates how to combine multiple factors to calculate composite scores and perform ranking. We assumed three nodes within service range:

After calculating scores by the established rules, we sort nodes by score and output the composite score for each. From this example, we see how different factors influence the final score. For instance, despite Node 2's greater distance, its preference and category bonus cause it to score higher than the closer Node 1. Node 3 also improves its ranking through manual bonus. This simple demonstration validates that the multi-factor model flexibly adjusts node order.

Note that in a real system we would use more rigorous geographic distance calculation (such as spherical distance formulas or GIS libraries) and tune parameters according to actual business needs. However, the above example suffices to illustrate the implementation logic: through a series of clear Python code, we express complex decision rules intuitively, facilitating future maintenance and adjustment.

Performance Optimization

Composite score ranking strategies introduce complexity in algorithms and data processing; therefore performance optimization is an important design consideration. Below are measures we adopted during implementation and optimization:

Through these measures, we ensured that the node ranking system performs well even with the introduction of complex logic. In fact, with proper methodology, multi-factor ranking does not necessarily incur unacceptable performance costs; conversely, because the algorithm is more refined, the system more accurately identifies the most suitable nodes, potentially reducing retry failures in downstream services and improving overall efficiency.

Summary and Future Outlook

In this technical practice, we centered on two key concepts—"geographic protection zones" and "multi-factor composite ranking"—introducing a node protection radius mechanism and establishing a weighted multi-factor scoring model. Through proper modeling and engineering implementation, we successfully enhanced the system's ability to support diverse business requirements, enabling node ranking to balance distance, exclusive service coverage, user preference, and operational control.

The entire design follows a clear hierarchy: first filter candidate nodes, then calculate multi-factor scores, finally rank by score. This workflow ensures result accuracy while enabling targeted optimization and adjustment at each stage. Through configurable parameters, we achieved flexible strategy adjustment, allowing rapid response to business strategy changes.

Looking forward, this multi-factor ranking system has room for further evolution. For example:

Each requirement change tests the system's resilience and architectural capability. This practice surrounding node protection radius and composite ranking deepened our appreciation for the importance of designing extension points upfront and maintaining strategy configurability. While meeting current requirements, we have also prepared the ground for future feature expansion. With continued optimization and evolution, we believe this system will better serve complex and changing business scenarios.

© 2026 Yuxu Ge ·