agentsclimarketplace

Backend principles

Skill Genuineh/fus/skills/backend-principles

Backend General Technical Principles. Covers async design, decoupling, microservices consistency, cloud-native robustness, and observability. Use for backend architecture decisions.From its SKILL.md

Install
npx -y skills add Genuineh/fus --skill backend-principles

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

5.3 KB, as published. Nobody here has run it

Backend Technical Principles

Comprehensive guide for backend technical principles.


1. Async Design

Core Principles

  • Non-blocking I/O: Use async APIs to handle I/O without blocking threads
  • Event-driven: Design around events for loose coupling
  • Backpressure: Handle slow consumers gracefully

Best Practices

// Good: Async handler
async fn get_user(id: i64) -> Result<User, Error> {
    let user = db.find_user(id).await?;
    Ok(user)
}

// Avoid: Blocking in async context
async fn bad_example() {
    let result = blocking_call(); // Blocks the runtime
}

When to Use Async

ScenarioRecommendation
I/O bound (DB, HTTP)Use async
CPU boundUse blocking or dedicated thread
Simple scriptsSync is fine

2. Decoupling & Separation of Concerns

Principles

  • Single Responsibility: Each service/component has one job
  • Dependency Inversion: Depend on abstractions, not concretions
  • Interface Segregation: Small, focused interfaces

Patterns

┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│   Layer A   │ ──▶ │   Layer B   │ ──▶ │   Layer C   │
└─────────────┘     └─────────────┘     └─────────────┘
       │                   │                   │
   Business Logic      Data Access       Presentation

Coupling Types

TypeDescriptionHow to Avoid
TemporalA waits for B to completeEvent-driven, async
DataShared data structuresAPI contracts
DomainShared business rulesBounded contexts

3. Microservices & Distributed Consistency

Consistency Patterns

PatternUse CaseTrade-off
Strong ConsistencyFinancial transactionsAvailability ↓
Eventual ConsistencySocial feedsTemporary inconsistency
Saga PatternCross-service transactionsComplexity ↑
CQRSRead/write separationConsistency challenges

Common Problems

  1. Distributed Transactions

    • Use Saga pattern
    • Implement compensation logic
    • Consider idempotency
  2. Network Partitions

    • Design for failure
    • Implement retry logic
    • Use circuit breakers
  3. Data Consistency

    • Event sourcing
    • Change data capture
    • Dual writes avoidance

4. Cloud-Native Robustness

Principles

  • Design for Failure: Assume anything can fail
  • Graceful Degradation: Partial functionality > complete failure
  • Horizontal Scaling: Stateless services
  • Self-Healing: Automatic recovery

Patterns

PatternDescription
Circuit BreakerPrevent cascading failures
BulkheadIsolate failures
Retry with BackoffHandle transient failures
TimeoutPrevent infinite waits
Rate LimitingProtect against overload

Implementation

// Circuit breaker concept
struct CircuitBreaker {
    failures: u32,
    state: CircuitState,
    threshold: u32,
}

impl CircuitBreaker {
    fn call<T>(&mut self, op: impl FnOnce() -> T) -> Result<T, Error> {
        match self.state {
            CircuitState::Open => Err(Error::CircuitOpen),
            CircuitState::HalfOpen => {
                // Try the call
                match op() {
                    Ok(r) => {
                        self.state = CircuitState::Closed;
                        Ok(r)
                    }
                    Err(e) => {
                        self.failures += 1;
                        if self.failures >= self.threshold {
                            self.state = CircuitState::Open;
                        }
                        Err(e)
                    }
                }
            }
            CircuitState::Closed => op(),
        }
    }
}

5. Observability

Three Pillars

PillarMetricsTools
LogsStructured eventsELK, Loki
MetricsNumeric aggregationsPrometheus, Grafana
TracesRequest flowJaeger, Zipkin

Best Practices

  1. Structured Logging

    {
      "timestamp": "2024-01-01T00:00:00Z",
      "level": "INFO",
      "message": "User logged in",
      "user_id": "123",
      "trace_id": "abc"
    }
    
  2. Metric Naming

    • Use suffixes: _total, _seconds, _bytes
    • Include units
    • Be consistent
  3. Distributed Tracing

    • Always include trace_id
    • Add context propagation
    • Instrument at boundaries

Key Metrics to Track

  • Latency (P50, P95, P99)
  • Error rate
  • Throughput (RPS)
  • Resource usage (CPU, Memory)
  • Queue depth

Validation Checklist

  • Async used appropriately for I/O
  • Components have clear responsibilities
  • Consistency model chosen for data
  • Circuit breakers implemented
  • Timeouts configured
  • Logs structured
  • Metrics exposed
  • Traces propagated

Keep looking

Skills are one crate of 607,533. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.