Chuyển đến nội dung
Skillpedia
Triển khai và đám mây (DevOps)48k · #4604

feature-flags

Skill này làm gì

Feature flags giống như các công tắc để bật hoặc tắt các phần của ứng dụng. Chúng cho phép bạn chỉ hiển thị tính năng mới cho một số người dùng hoặc vào những thời điểm nhất định, mà không cần thay đổi mã chính.

Khi nào nên dùng

  • ✓Khi ra mắt một tính năng mới cho một nhóm nhỏ người dùng trước.
  • ✓Khi thử nghiệm hai phiên bản của một tính năng để xem phiên bản nào hoạt động tốt hơn.
  • ✓Khi nhanh chóng tắt một tính năng đang gây ra sự cố.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/feature-flags/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/feature-flags/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bật tính năng thanh toán mới cho người dùng cao cấp.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Bạn thiết lập một dịch vụ feature flag và, trong mã, kiểm tra xem cờ có đang bật cho người dùng hiện tại hay không. Nếu có, mã mới sẽ chạy; nếu không, mã cũ được sử dụng.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Feature Flags

Control feature releases and enable progressive rollout with feature flag systems.

Prerequisites

  • Application code access
  • Feature flag service or self-hosted solution
  • Basic understanding of deployment patterns

Feature Flag Types

Type Purpose Example
Release Control feature visibility New checkout flow
Experiment A/B testing Button color test
Ops Runtime configuration Rate limiting
Permission User access control Premium features
Kill Switch Emergency disable Third-party integration

LaunchDarkly

SDK Setup (Node.js)

const LaunchDarkly = require('launchdarkly-node-server-sdk');

const client = LaunchDarkly.init(process.env.LAUNCHDARKLY_SDK_KEY);

await client.waitForInitialization();

// Evaluate flag
const user = {
  key: 'user-123',
  email: 'user@example.com',
  custom: {
    plan: 'premium',
    company: 'acme'
  }
};

const showNewFeature = await client.variation('new-checkout', user, false);

if (showNewFeature) {
  // New feature code
} else {
  // Existing code
}

React SDK

import { withLDProvider, useFlags, useLDClient } from 'launchdarkly-react-client-sdk';

// Provider setup
export default withLDProvider({
  clientSideID: 'your-client-side-id',
  user: {
    key: 'user-123',
    email: 'user@example.com'
  }
})(App);

// Using flags in component
function FeatureComponent() {
  const { newCheckout, experimentVariant } = useFlags();
  const ldClient = useLDClient();

  // Track events
  const handleClick = () => {
    ldClient.track('checkout-started');
  };

  if (newCheckout) {
    return <NewCheckout onClick={handleClick} />;
  }
  return <OldCheckout onClick={handleClick} />;
}

Targeting Rules

# LaunchDarkly targeting configuration
flag: new-checkout
targeting:
  # Individual users
  targets:
    - variation: true
      values: ['user-123', 'user-456']
  
  # Rules
  rules:
    # Beta users
    - variation: true
      clauses:
        - attribute: email
          op: endsWith
          values: ['@company.com']
    
    # Premium plan
    - variation: true
      clauses:
        - attribute: plan
          op: in
          values: ['premium', 'enterprise']
    
    # Percentage rollout
    - variation: true
      rollout:
        variations:
          - variation: true
            weight: 20000  # 20%
          - variation: false
            weight: 80000  # 80%
  
  # Default
  fallthrough:
    variation: false

Unleash

Server Setup

# docker-compose.yml
version: '3.8'

services:
  unleash:
    image: unleashorg/unleash-server:latest
    ports:
      - "4242:4242"
    environment:
      - DATABASE_URL=postgres://postgres:password@db/unleash
      - DATABASE_SSL=false
    depends_on:
      - db

  db:
    image: postgres:15
    environment:
      - POSTGRES_PASSWORD=password
      - POSTGRES_DB=unleash
    volumes:
      - postgres-data:/var/lib/postgresql/data

volumes:
  postgres-data:

SDK Setup (Node.js)

const { initialize } = require('unleash-client');

const unleash = initialize({
  url: 'http://localhost:4242/api',
  appName: 'my-app',
  customHeaders: {
    Authorization: 'your-api-token'
  }
});

unleash.on('ready', () => {
  // Check feature
  const isEnabled = unleash.isEnabled('new-checkout');
  
  // With context
  const context = {
    userId: 'user-123',
    properties: {
      plan: 'premium'
    }
  };
  
  const isEnabledForUser = unleash.isEnabled('new-checkout', context);
  
  // Get variant
  const variant = unleash.getVariant('experiment-flag', context);
  console.log(variant.name); // 'control' or 'treatment'
});

Activation Strategies

# Standard strategies
strategies:
  - name: default
    # On/off for everyone
    
  - name: userWithId
    parameters:
      userIds: 'user-1,user-2,user-3'
    
  - name: gradualRolloutUserId
    parameters:
      percentage: 25
      groupId: 'new-feature'
    
  - name: gradualRolloutRandom
    parameters:
      percentage: 50
    
  - name: flexibleRollout
    parameters:
      rollout: 30
      stickiness: userId
      groupId: 'checkout-exp'

Custom Implementation

Database-Backed Flags

# models.py
from django.db import models

class FeatureFlag(models.Model):
    name = models.CharField(max_length=100, unique=True)
    enabled = models.BooleanField(default=False)

…
Câu hỏi thường gặp

'Progressive rollout' là gì?

Đó là việc phát hành một tính năng mới theo từng bước, bắt đầu với một số ít người dùng và tăng dần theo thời gian, để giảm thiểu rủi ro.

Tôi có thể dùng cờ để tắt tính năng không?

Có, chúng hoạt động như 'công tắc khẩn cấp' để vô hiệu hóa tính năng trong trường hợp khẩn cấp.

Tôi có cần là lập trình viên có kinh nghiệm để dùng không?

Hiểu biết cơ bản về cách mã hoạt động sẽ có ích, nhưng dịch vụ cờ tính năng đơn giản hóa quá trình kiểm soát.

Chi tiết

Mô tả gốc của tác giả

Implement feature flags for progressive feature rollout using LaunchDarkly, Unleash, or custom solutions.

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#4604
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự