Introduction to DarkFeature
DarkFeature is a powerful feature flag and experimentation platform that helps you ship features safely, measure their impact, and learn from your releases. Whether you’re a startup or an enterprise, DarkFeature provides the tools you need to make data-driven decisions about your product.
What is DarkFeature?
DarkFeature allows you to:
- Deploy features safely - Roll out new features gradually to reduce risk
- Test in production - Enable features for specific users or percentages
- Measure impact - Track how features affect user behavior and business metrics
- Learn and iterate - Use data to make informed decisions about your product
Core Concepts
Feature Flags
Feature flags (also called feature toggles) allow you to turn features on and off without deploying new code. This gives you control over when and how features are released to your users.
// Check if a feature is enabled
const client = new DarkFeatureClient({
apiKey: 'your-api-key',
context: { userId: '123' },
})
const isEnabled = await client.getFeature('new-navigation', { fallback: false })
if (isEnabled) {
showNewNavigation()
} else {
showOldNavigation()
}
Percentage Rollouts
Gradually roll out features to a percentage of your user base. Start with a small percentage and increase it as you gain confidence.
// The platform automatically handles percentage rollouts
// Configure in the dashboard to roll out to 10% of users
const isEnabled = await client.getFeature('new-feature', { fallback: false })
Targeting Rules
Target specific users based on their attributes, behavior, or other criteria.
// Enable for premium users
const isEnabled = await client.getFeature('premium-feature', {
fallback: false,
context: { plan: 'premium' },
})
Real-time Analytics
Monitor feature usage and performance in real-time to understand the impact of your changes.
How DarkFeature Works
DarkFeature follows a simple architecture:
- Create Features - Define feature flags in the DarkFeature dashboard
- Configure Rules - Set up targeting rules and rollout percentages
- Install Code Examples - Add DarkFeature to your application
- Evaluate Flags - Check feature flags in your code
- Monitor Results - Track usage and performance metrics
Architecture Overview
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Your App │ │ DarkFeature │ │ Dashboard │
│ │ │ Code Example │ │ │
│ ┌─────────────┐ │ │ ┌─────────────┐ │ │ ┌─────────────┐ │
│ │ Feature │ │◄──►│ │ Flag │ │ │ │ Create & │ │
│ │ Evaluation │ │ │ │ Evaluation │ │◄──►│ │ Configure │ │
│ └─────────────┘ │ │ └─────────────┘ │ │ └─────────────┘ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
Key Benefits
For Developers
- Safer Deployments - Deploy code without immediately exposing new features
- Faster Iteration - Test and iterate on features without full deployments
- Better Testing - Test features in production with real users
- Reduced Risk - Quickly disable problematic features
For Product Teams
- Data-Driven Decisions - Make decisions based on real user data
- Gradual Rollouts - Reduce risk by rolling out features slowly
- A/B Testing - Test different versions of features
- User Targeting - Deliver personalized experiences
For Operations
- Kill Switches - Quickly disable features during incidents
- Monitoring - Track feature performance and usage
- Compliance - Control feature access for compliance requirements
- Audit Trail - Track all feature changes and decisions
Getting Started
1. Create an Account
Sign up for DarkFeature at darkfeature.com and create your first project.
2. Create Your First Feature
In the DarkFeature dashboard, create a feature flag for a new feature you want to roll out.
3. Install Code Examples
Add DarkFeature to your application using one of our code examples:
- JavaScript/TypeScript - For web applications
- React - For React applications
- Node.js - For server-side applications
- Mobile - For iOS and Android apps
4. Evaluate Features
Start checking feature flags in your code:
import { DarkFeatureClient } from '@darkfeature/sdk-javascript'
const client = new DarkFeatureClient({
apiKey: 'your-api-key',
context: { userId: '123' },
})
// Check if a feature is enabled
const isEnabled = await client.getFeature('my-feature', { fallback: false })
if (isEnabled) {
// Show new feature
} else {
// Show old feature
}
5. Monitor and Iterate
Track how your features perform and use the data to make decisions about your product.
Use Cases
Feature Rollouts
Gradually roll out new features to reduce risk and gather feedback.
// Configure in dashboard to roll out new navigation to 20% of users
const showNewNav = await client.getFeature('new-navigation', {
fallback: false,
})
if (showNewNav) {
renderNewNavigation()
} else {
renderOldNavigation()
}
Kill Switches
Quickly disable features during incidents or when issues are discovered.
// Emergency kill switch
const emergencyMode = await client.getFeature('emergency-disable', {
fallback: false,
})
if (emergencyMode) {
disableFeature()
showMaintenanceMessage()
}
User Targeting
Deliver personalized experiences based on user attributes.
// Enable premium features for premium users
const hasPremiumFeatures = await client.getFeature('premium-features', {
fallback: false,
context: { plan: 'premium' },
})
if (hasPremiumFeatures) {
showPremiumFeatures()
}
Configuration Management
Use feature flags to manage configuration values.
// Get configuration values
const maxRetries = await client.getFeature('max-retries', { fallback: 3 })
const timeout = await client.getFeature('request-timeout', { fallback: 5000 })
const apiClient = new ApiClient({
maxRetries,
timeout,
})
Multiple Features
Evaluate multiple features efficiently in a single request.
// Get multiple features at once
const features = await client.getFeatures({
features: {
'new-navigation': false,
'dark-mode': false,
'premium-features': false,
},
context: { userId: '123' },
})
if (features['new-navigation']) {
applyNewNavigation()
}
if (features['dark-mode']) {
applyDarkTheme()
}
if (features['premium-features']) {
showPremiumFeatures()
}
Code Examples Overview
Client-Side (Browser)
For web applications, use the JavaScript SDK:
import { DarkFeatureClient } from '@darkfeature/sdk-javascript'
const client = new DarkFeatureClient({
apiKey: process.env.DARKFEATURE_CLIENT_API_KEY,
context: {
userId: '123',
email: '[email protected]',
},
})
const isEnabled = await client.getFeature('new-feature', { fallback: false })
React Applications
For React applications, use the React SDK:
import { DarkFeatureProvider, useFeature } from '@darkfeature/sdk-react'
function App() {
return (
<DarkFeatureProvider
config={{
apiKey: 'your-api-key',
context: { userId: '123' },
}}>
<MyComponent />
</DarkFeatureProvider>
)
}
function MyComponent() {
const { feature: isEnabled } = useFeature('new-feature', { fallback: false })
return isEnabled ? <NewFeature /> : <OldFeature />
}
Server-Side (Node.js)
For server-side applications, use the JavaScript SDK:
import { DarkFeatureClient } from '@darkfeature/sdk-javascript'
const client = new DarkFeatureClient({
apiKey: process.env.DARKFEATURE_API_KEY,
context: {
userId: '123',
email: '[email protected]',
},
})
// Express.js middleware
app.use(async (req, res, next) => {
req.features = await client.getFeatures({
features: {
'new-navigation': false,
'premium-features': false,
},
context: { userId: req.user?.id },
})
next()
})
Best Practices
Naming Conventions
- Use descriptive, lowercase names with hyphens
- Include the feature name and environment
- Examples:
new-navigation
,beta-features
,dark-mode
Flag Lifecycle
- Development - Create and test flags locally
- Staging - Test flags in staging environment
- Production - Roll out flags to production users
- Cleanup - Remove flags when no longer needed
Testing
- Test flags in all environments
- Use feature flags in your test suite
- Mock flags for unit tests
- Test both enabled and disabled states
// Mock client for testing
class MockDarkFeatureClient {
constructor(mockFlags = {}) {
this.mockFlags = mockFlags
}
async getFeature(featureName, options = {}) {
return this.mockFlags[featureName] ?? options.fallback
}
}
const mockClient = new MockDarkFeatureClient({
'new-feature': true,
'premium-features': false,
})
Monitoring
- Monitor flag evaluation times
- Track flag usage and performance
- Set up alerts for unusual patterns
- Review and clean up unused flags
Error Handling
Always provide fallback values to ensure your application continues to work even if feature flag evaluation fails:
try {
const isEnabled = await client.getFeature('new-feature', { fallback: false })
// Use feature
} catch (error) {
console.error('Feature flag error:', error)
// Fallback to default behavior
showDefaultFeature()
}
Context Management
Provide relevant user context for better targeting:
// Set context for the current user
client.setContext({
userId: user.id,
email: user.email,
plan: user.plan,
country: user.country,
userAgent: navigator.userAgent,
})
// All subsequent feature evaluations will use this context
const isEnabled = await client.getFeature('premium-features', {
fallback: false,
})
Next Steps
- Quick Start Guide - Get up and running in minutes
- Client-Side Code Examples - Choose your platform and integrate
- Server-Side Code Examples - Backend integration
- Platform Overview - Learn about advanced features
- Best Practices - Follow proven patterns
Support
- Documentation - Comprehensive guides and examples
- Community - Connect with other users
- Support - Get help from our team
- API Reference - Detailed API documentation