Affiliate Service
The Affiliate Service is responsible for managing the entire affiliate marketing program at Komerce. This includes generating unique referral links, tracking clicks and conversions, and calculating commissions for our affiliate partners.
Core Responsibilities
Section titled “Core Responsibilities”- Link Generation: Creates unique, trackable links for each affiliate partner.
- Referral Tracking: Monitors clicks on affiliate links and attributes successful conversions (e.g., sign-ups, purchases).
- Commission Calculation: Automatically calculates commissions based on predefined rules and successful referrals.
- Payout Management: Tracks payable commissions and integrates with payment systems for affiliate payouts.
Technology Stack
Section titled “Technology Stack”- Language & Framework: Node.js with Express.js
- Database: PostgreSQL for storing affiliate data, referral records, and commission details.
- Caching: Redis for caching frequently accessed data.
- Messaging: RabbitMQ for asynchronous communication, such as processing commission calculations after an order is completed.
Architecture Overview
Section titled “Architecture Overview”The service operates as a standalone microservice. It exposes a REST API and communicates with other services (like the Order Service) asynchronously via a message broker to ensure loose coupling and scalability.
Here is a simple flow diagram illustrating a referral:
sequenceDiagram participant User participant AffiliateService as Affiliate Service participant OrderService as Order Service
User->>+AffiliateService: Clicks affiliate link AffiliateService->>-User: Records click, sets tracking cookie, redirects to product User->>+OrderService: Completes a purchase OrderService->>-User: Confirms order OrderService->>AffiliateService: Publishes 'OrderCompleted' event AffiliateService->>AffiliateService: Consumes event, calculates commission
API Endpoints
Section titled “API Endpoints”Method | Endpoint | Description |
---|---|---|
POST | /api/v1/affiliate/links | Generates a new affiliate link. |
GET | /api/v1/affiliate/stats | Retrieves performance statistics. |
GET | /api/v1/affiliate/payouts | Fetches payout history for an affiliate. |