Skip to main content

TekTree Event Catalog

Version: 1.0.0 Last Updated: 2025-12-16 Status: Foundation (Pre-Implementation)

Document Purpose

This document serves as the complete catalog of domain events in the TekTree platform. It defines event schemas, producers, consumers, choreography patterns, versioning strategy, and retention policies.

Event Taxonomy

Events are organized by domain and follow a hierarchical naming convention: Format: {domain}.{aggregate}.{action} Examples:
  • user.registered
  • knowledge.question.posted
  • gamification.achievement.unlocked
  • payment.subscription.upgraded

Event Schema Standards

All events follow this base schema:
{
  "event_id": "evt_abc123xyz",
  "event_type": "user.registered",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T14:30:00Z",
  "trace_id": "trace_abc123",
  "correlation_id": "corr_xyz789",
  "source_service": "user-service",
  "producer_id": "user-svc-pod-1",
  "metadata": {
    "user_id": "usr_123",
    "ip_address": "203.0.113.42",
    "user_agent": "Mozilla/5.0..."
  },
  "payload": {
    // Event-specific data
  }
}
Required Fields:
  • event_id: Unique identifier (UUID v4)
  • event_type: Event type (dot notation)
  • event_version: Semantic version of event schema
  • timestamp: ISO 8601 UTC timestamp
  • source_service: Service that emitted the event
  • payload: Event-specific data
Optional Fields:
  • trace_id: Distributed tracing ID
  • correlation_id: Links related events
  • producer_id: Instance that produced event
  • metadata: Contextual information (user, IP, etc.)

1. User Domain Events

Event: user.registered

Version: 1.0.0 Producer: User Service Consumers: Gamification Service, Payment Service, Email Service Description: Emitted when a new user successfully completes registration. Schema:
{
  "event_type": "user.registered",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T14:30:00Z",
  "payload": {
    "user_id": "usr_abc123",
    "email": "user@example.com",
    "handle": "johndoe",
    "email_verified": false,
    "registration_source": "web",
    "referrer": "organic",
    "initial_tier": "free"
  }
}
Consumer Actions:
  • Gamification Service: Award +100 XP welcome bonus
  • Payment Service: Create free tier subscription
  • Email Service: Send welcome email + verification email

Event: user.profile.updated

Version: 1.0.0 Producer: User Service Consumers: Search Service, Cache Service Description: Emitted when user updates their profile information. Schema:
{
  "event_type": "user.profile.updated",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T14:35:00Z",
  "payload": {
    "user_id": "usr_abc123",
    "updated_fields": ["first_name", "bio", "avatar"],
    "old_values": {
      "first_name": "John",
      "bio": null,
      "avatar": null
    },
    "new_values": {
      "first_name": "Jonathan",
      "bio": "Software engineer passionate about...",
      "avatar": "https://cdn.tektree.com/avatars/usr_abc123.jpg"
    }
  }
}
Consumer Actions:
  • Search Service: Reindex user profile
  • Cache Service: Invalidate user profile cache

Event: user.authenticated

Version: 1.0.0 Producer: User Service Consumers: Analytics Service, Gamification Service (streak tracking) Description: Emitted when user successfully logs in. Schema:
{
  "event_type": "user.authenticated",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T15:00:00Z",
  "payload": {
    "user_id": "usr_abc123",
    "session_id": "sess_xyz789",
    "auth_method": "email_password",
    "ip_address": "203.0.113.42",
    "device_type": "desktop",
    "user_agent": "Mozilla/5.0...",
    "location": {
      "country": "US",
      "city": "San Francisco"
    }
  }
}
Consumer Actions:
  • Analytics Service: Track active users (DAU)
  • Gamification Service: Update streak (daily activity)

2. Knowledge Domain Events

Event: knowledge.question.posted

Version: 1.0.0 Producer: Knowledge Service Consumers: Gamification Service, Search Service, Notification Service Description: Emitted when a user posts a new question. Schema:
{
  "event_type": "knowledge.question.posted",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T15:30:00Z",
  "payload": {
    "question_id": "qst_abc123",
    "user_id": "usr_abc123",
    "title": "How do I implement event sourcing in Go?",
    "body": "I'm building an event-driven system...",
    "tags": ["go", "event-sourcing", "architecture"],
    "areas": ["area_programming", "area_go"],
    "visibility": "public",
    "files": [
      {
        "file_id": "file_xyz",
        "file_name": "diagram.png",
        "file_size": 1024000,
        "mime_type": "image/png"
      }
    ]
  }
}
Consumer Actions:
  • Gamification Service: Award +5 XP to user
  • Search Service: Index question for search
  • Notification Service: Notify followers of related areas

Event: knowledge.answer.submitted

Version: 1.0.0 Producer: Knowledge Service Consumers: Gamification Service, Notification Service Description: Emitted when a user submits an answer to a question. Schema:
{
  "event_type": "knowledge.answer.submitted",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T16:00:00Z",
  "payload": {
    "answer_id": "ans_def456",
    "question_id": "qst_abc123",
    "user_id": "usr_xyz789",
    "body": "Here's how you can implement event sourcing...",
    "code_snippets": [
      {
        "language": "go",
        "code": "type Event struct {...}"
      }
    ]
  }
}
Consumer Actions:
  • Gamification Service: Award +10 XP to answerer
  • Notification Service: Notify question author

Event: knowledge.answer.accepted

Version: 1.0.0 Producer: Knowledge Service Consumers: Gamification Service, Notification Service Description: Emitted when question author accepts an answer as the best answer. Schema:
{
  "event_type": "knowledge.answer.accepted",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T16:30:00Z",
  "payload": {
    "answer_id": "ans_def456",
    "question_id": "qst_abc123",
    "question_author": "usr_abc123",
    "answer_author": "usr_xyz789"
  }
}
Consumer Actions:
  • Gamification Service: Award +50 XP to answer author
  • Notification Service: Notify answer author

Event: knowledge.insight.published

Version: 1.0.0 Producer: Knowledge Service Consumers: Gamification Service, Search Service, Notification Service Description: Emitted when a user publishes an insight. Schema:
{
  "event_type": "knowledge.insight.published",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T17:00:00Z",
  "payload": {
    "insight_id": "ins_ghi789",
    "user_id": "usr_abc123",
    "title": "Event-Driven Architecture Best Practices",
    "body": "# Introduction\n\nEvent-driven architecture...",
    "insight_type": "article",
    "tags": ["architecture", "events", "best-practices"],
    "areas": ["area_architecture"],
    "co_authors": [],
    "estimated_read_time_minutes": 10
  }
}
Consumer Actions:
  • Gamification Service: Award +25 XP
  • Search Service: Index insight
  • Notification Service: Notify followers

Event: knowledge.discussion.started

Version: 1.0.0 Producer: Knowledge Service Consumers: Gamification Service, Search Service, Notification Service Description: Emitted when a user starts a discussion. Schema:
{
  "event_type": "knowledge.discussion.started",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T17:30:00Z",
  "payload": {
    "discussion_id": "dsc_jkl012",
    "user_id": "usr_abc123",
    "question": "What's your favorite Go web framework?",
    "description": "I'm evaluating frameworks for a new project...",
    "poll_options": ["Gin", "Echo", "Fiber", "Chi"],
    "tags": ["go", "web-frameworks"],
    "areas": ["area_go"]
  }
}
Consumer Actions:
  • Gamification Service: Award +10 XP
  • Search Service: Index discussion
  • Notification Service: Notify area followers

Event: knowledge.resource.shared

Version: 1.0.0 Producer: Knowledge Service Consumers: Gamification Service, Search Service Description: Emitted when a user shares a resource. Schema:
{
  "event_type": "knowledge.resource.shared",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T18:00:00Z",
  "payload": {
    "resource_id": "res_mno345",
    "user_id": "usr_abc123",
    "resource_type": "course",
    "title": "Complete Guide to Event Sourcing",
    "url": "https://example.com/course",
    "description": "Comprehensive course on event sourcing...",
    "tags": ["event-sourcing", "cqrs"],
    "areas": ["area_architecture"],
    "metadata": {
      "author": "Martin Fowler",
      "duration_hours": 10,
      "price_usd": 49.99
    }
  }
}
Consumer Actions:
  • Gamification Service: Award +5 XP
  • Search Service: Index resource

3. Social Domain Events

Event: social.content.liked

Version: 1.0.0 Producer: Knowledge Service Consumers: Gamification Service, Notification Service Description: Emitted when a user likes content. Schema:
{
  "event_type": "social.content.liked",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T18:30:00Z",
  "payload": {
    "like_id": "lke_pqr678",
    "content_type": "question",
    "content_id": "qst_abc123",
    "content_author": "usr_abc123",
    "liker_user_id": "usr_xyz789"
  }
}
Consumer Actions:
  • Gamification Service: Award +2 XP to content author
  • Notification Service: Notify content author (batched)

Event: social.comment.added

Version: 1.0.0 Producer: Knowledge Service Consumers: Gamification Service, Notification Service Description: Emitted when a user adds a comment. Schema:
{
  "event_type": "social.comment.added",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T19:00:00Z",
  "payload": {
    "comment_id": "cmt_stu901",
    "content_type": "insight",
    "content_id": "ins_ghi789",
    "content_author": "usr_abc123",
    "commenter_user_id": "usr_xyz789",
    "body": "Great article! I've been implementing this...",
    "parent_comment_id": null
  }
}
Consumer Actions:
  • Gamification Service: Award +3 XP to commenter
  • Notification Service: Notify content author and parent commenter

Event: social.content.upvoted

Version: 1.0.0 Producer: Knowledge Service Consumers: Gamification Service, Notification Service Description: Emitted when a user upvotes content. Schema:
{
  "event_type": "social.content.upvoted",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T19:30:00Z",
  "payload": {
    "vote_id": "vte_vwx234",
    "content_type": "answer",
    "content_id": "ans_def456",
    "content_author": "usr_xyz789",
    "voter_user_id": "usr_abc123",
    "vote_value": 1
  }
}
Consumer Actions:
  • Gamification Service: Award +5 XP to content author
  • Notification Service: Notify content author (batched)

Event: social.user.followed

Version: 1.0.0 Producer: User Service Consumers: Gamification Service, Notification Service Description: Emitted when a user follows another user. Schema:
{
  "event_type": "social.user.followed",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T20:00:00Z",
  "payload": {
    "follower_user_id": "usr_abc123",
    "followed_user_id": "usr_xyz789"
  }
}
Consumer Actions:
  • Gamification Service: Check follower milestones (10, 100, 1000 followers)
  • Notification Service: Notify followed user

4. Gamification Domain Events

Event: gamification.xp.earned

Version: 1.0.0 Producer: Gamification Service Consumers: Real-Time Service, Notification Service Description: Emitted when a user earns XP. Schema:
{
  "event_type": "gamification.xp.earned",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T20:30:00Z",
  "payload": {
    "transaction_id": "xp_txn_abc123",
    "user_id": "usr_abc123",
    "xp_amount": 25,
    "xp_source": "insight_published",
    "related_entity_id": "ins_ghi789",
    "total_xp_after": 1025,
    "daily_xp_earned_today": 75
  }
}
Consumer Actions:
  • Real-Time Service: Push XP notification to user’s active WebSocket
  • Notification Service: Add to notification feed

Event: gamification.level.up

Version: 1.0.0 Producer: Gamification Service Consumers: Real-Time Service, Notification Service, User Service Description: Emitted when a user levels up. Schema:
{
  "event_type": "gamification.level.up",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T21:00:00Z",
  "payload": {
    "user_id": "usr_abc123",
    "old_level": 4,
    "new_level": 5,
    "level_title": "Growing Tree",
    "xp_required_for_next": 1000,
    "unlocked_features": ["downvote", "create_collections"]
  }
}
Consumer Actions:
  • Real-Time Service: Show level-up animation
  • Notification Service: Send congratulatory notification
  • User Service: Update user level badge

Event: gamification.achievement.unlocked

Version: 1.0.0 Producer: Gamification Service Consumers: Real-Time Service, Notification Service Description: Emitted when a user unlocks an achievement. Schema:
{
  "event_type": "gamification.achievement.unlocked",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T21:30:00Z",
  "payload": {
    "achievement_id": "ach_week_warrior",
    "user_id": "usr_abc123",
    "achievement_name": "Week Warrior",
    "achievement_description": "Maintain a 7-day activity streak",
    "achievement_tier": "gold",
    "xp_bonus": 100,
    "badge_image_url": "https://cdn.tektree.com/badges/week_warrior.svg"
  }
}
Consumer Actions:
  • Real-Time Service: Show achievement unlock animation
  • Notification Service: Send achievement notification

Event: gamification.streak.extended

Version: 1.0.0 Producer: Gamification Service Consumers: Real-Time Service Description: Emitted when a user extends their daily streak. Schema:
{
  "event_type": "gamification.streak.extended",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T22:00:00Z",
  "payload": {
    "user_id": "usr_abc123",
    "streak_count": 7,
    "streak_milestone": true,
    "xp_bonus": 100
  }
}
Consumer Actions:
  • Real-Time Service: Update streak counter UI

Event: gamification.leaderboard.updated

Version: 1.0.0 Producer: Gamification Service Consumers: Real-Time Service Description: Emitted when leaderboard rankings change (throttled to avoid spam). Schema:
{
  "event_type": "gamification.leaderboard.updated",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T22:30:00Z",
  "payload": {
    "leaderboard_type": "weekly_xp",
    "top_users": [
      {
        "user_id": "usr_abc123",
        "rank": 1,
        "xp": 5000
      },
      {
        "user_id": "usr_xyz789",
        "rank": 2,
        "xp": 4800
      }
    ]
  }
}
Consumer Actions:
  • Real-Time Service: Push leaderboard updates to subscribed clients

5. Payment Domain Events

Event: payment.subscription.created

Version: 1.0.0 Producer: Payment Service Consumers: User Service, Analytics Service Description: Emitted when a subscription is created (including free tier). Schema:
{
  "event_type": "payment.subscription.created",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T23:00:00Z",
  "payload": {
    "subscription_id": "sub_yzabcd",
    "user_id": "usr_abc123",
    "tier": "free",
    "billing_cycle": "monthly",
    "start_date": "2025-12-16T23:00:00Z",
    "trial_ends_at": null,
    "quotas": {
      "areas": 10,
      "questions_per_month": 20,
      "insights_per_month": 5,
      "storage_mb": 100
    }
  }
}
Consumer Actions:
  • User Service: Update user tier badge
  • Analytics Service: Track subscription creation

Event: payment.subscription.upgraded

Version: 1.0.0 Producer: Payment Service Consumers: User Service, Gamification Service, Notification Service Description: Emitted when a user upgrades their subscription tier. Schema:
{
  "event_type": "payment.subscription.upgraded",
  "event_version": "1.0.0",
  "timestamp": "2025-12-16T23:30:00Z",
  "payload": {
    "subscription_id": "sub_yzabcd",
    "user_id": "usr_abc123",
    "old_tier": "free",
    "new_tier": "pro",
    "effective_date": "2025-12-16T23:30:00Z",
    "prorated_charge": 9.00,
    "new_quotas": {
      "areas": "unlimited",
      "questions_per_month": 200,
      "insights_per_month": 50,
      "storage_mb": 10240
    }
  }
}
Consumer Actions:
  • User Service: Update user tier badge
  • Gamification Service: Award +200 XP bonus
  • Notification Service: Send upgrade confirmation

Event: payment.quota.exceeded

Version: 1.0.0 Producer: Payment Service (quota check) Consumers: Notification Service Description: Emitted when a user exceeds their quota limit. Schema:
{
  "event_type": "payment.quota.exceeded",
  "event_version": "1.0.0",
  "timestamp": "2025-12-17T00:00:00Z",
  "payload": {
    "user_id": "usr_abc123",
    "tier": "free",
    "quota_type": "questions_per_month",
    "quota_limit": 20,
    "current_usage": 21,
    "action_blocked": true
  }
}
Consumer Actions:
  • Notification Service: Send upgrade prompt notification

Event: payment.webhook.received

Version: 1.0.0 Producer: Payment Service Consumers: Analytics Service (for auditing) Description: Emitted when a Polar webhook is received (for audit trail). Schema:
{
  "event_type": "payment.webhook.received",
  "event_version": "1.0.0",
  "timestamp": "2025-12-17T00:30:00Z",
  "payload": {
    "webhook_id": "whk_efghij",
    "polar_event_type": "checkout.completed",
    "polar_event_id": "evt_polar_123",
    "signature_valid": true,
    "processed": true
  }
}
Consumer Actions:
  • Analytics Service: Log webhook for debugging

6. Real-Time Domain Events

Event: realtime.user.joined

Version: 1.0.0 Producer: Real-Time Service Consumers: Analytics Service Description: Emitted when a user joins a real-time channel (presence). Schema:
{
  "event_type": "realtime.user.joined",
  "event_version": "1.0.0",
  "timestamp": "2025-12-17T01:00:00Z",
  "payload": {
    "user_id": "usr_abc123",
    "channel": "content:qst_abc123",
    "connection_id": "conn_klmnop"
  }
}
Consumer Actions:
  • Analytics Service: Track real-time engagement

Event: notification.sent

Version: 1.0.0 Producer: Notification Service Consumers: Analytics Service Description: Emitted when a notification is successfully sent. Schema:
{
  "event_type": "notification.sent",
  "event_version": "1.0.0",
  "timestamp": "2025-12-17T01:30:00Z",
  "payload": {
    "notification_id": "ntf_qrstuv",
    "user_id": "usr_abc123",
    "notification_type": "achievement_unlocked",
    "delivery_method": "websocket",
    "delivered": true
  }
}
Consumer Actions:
  • Analytics Service: Track notification engagement

Event Choreography Patterns

Pattern 1: User Registration Flow

Pattern 2: Content Engagement Flow

Pattern 3: Achievement Unlock Flow


Event Versioning Strategy

Semantic Versioning

Events follow semantic versioning (MAJOR.MINOR.PATCH):
  • MAJOR: Breaking changes (field removed, type changed)
  • MINOR: Backward-compatible additions (new field)
  • PATCH: Documentation or clarification changes

Versioning Rules

  1. Always include event_version field in event payload
  2. Consumers must handle multiple versions gracefully
  3. Deprecated versions supported for 6 months before removal
  4. Breaking changes require migration plan

Example: Adding a New Field (Minor Version)

v1.0.0:
{
  "event_type": "user.registered",
  "event_version": "1.0.0",
  "payload": {
    "user_id": "usr_abc123",
    "email": "user@example.com"
  }
}
v1.1.0 (Add new field):
{
  "event_type": "user.registered",
  "event_version": "1.1.0",
  "payload": {
    "user_id": "usr_abc123",
    "email": "user@example.com",
    "referral_code": "REF123"  // New field
  }
}
Consumer Handling:
type UserRegisteredV1 struct {
    UserID string `json:"user_id"`
    Email  string `json:"email"`
    ReferralCode string `json:"referral_code,omitempty"` // Optional
}

func handleUserRegistered(event Event) {
    var payload UserRegisteredV1
    json.Unmarshal(event.Payload, &payload)

    // Handle with or without referral_code
    if payload.ReferralCode != "" {
        // Process referral
    }
}

Event Retention Policies

Event CategoryRetention PeriodStorageRationale
User eventsIndefiniteEvent StoreAudit trail
Knowledge eventsIndefiniteEvent StoreContent history
Gamification events2 yearsEvent StoreHistorical analytics
Payment events7 yearsEvent StoreLegal compliance
Social events1 yearEvent StoreRecent activity
Real-time events7 daysRedis StreamsOperational only
Notification events30 daysMongoDBRecent history
Archival Strategy:
  • Events older than retention period moved to cold storage (S3)
  • Archived events compressed (gzip)
  • Archived events indexed for compliance queries
  • Automatic archival job runs weekly

Event Publishing Guarantees

At-Least-Once Delivery

TekTree uses at-least-once delivery semantics:
  • Events may be delivered multiple times
  • Consumers must be idempotent
  • Use event_id for deduplication

Idempotency Pattern

type EventProcessor struct {
    processedEvents *sync.Map
}

func (p *EventProcessor) ProcessEvent(event Event) error {
    // Check if already processed
    if _, exists := p.processedEvents.Load(event.EventID); exists {
        log.Info("Event already processed, skipping", "event_id", event.EventID)
        return nil
    }

    // Process event
    if err := p.doProcess(event); err != nil {
        return err
    }

    // Mark as processed
    p.processedEvents.Store(event.EventID, time.Now())
    return nil
}

Event Ordering Guarantees

Per-Aggregate Ordering

Events for the same aggregate are processed in order:
  • Use correlation_id to group related events
  • Redis Streams guarantees order within a stream
  • Consumers use consumer groups for parallel processing

Global Ordering

Global ordering is not guaranteed:
  • Events from different services may arrive out of order
  • Use timestamps for eventual consistency
  • Design for commutative operations where possible

Dead Letter Queue (DLQ)

DLQ Policy

Events that fail processing after 3 retries are moved to DLQ:
  1. First retry: Immediate
  2. Second retry: 10 seconds delay
  3. Third retry: 60 seconds delay
  4. If still failing: Move to DLQ

DLQ Monitoring

  • Alert when DLQ size > 100
  • Daily DLQ report sent to operations team
  • Manual review and reprocessing

Event Bus Performance Targets

MetricTarget
Event publishing latency (p95)< 10ms
Event delivery latency (p95)< 100ms
Throughput (sustained)1,000 events/sec
Throughput (burst)5,000 events/sec
Event backlog size (max)10,000 events

Event Catalog Maintenance

Ownership

  • Domain Event Owner: Team responsible for the domain (User, Knowledge, etc.)
  • Event Catalog Maintainer: Platform team
  • Review Frequency: Quarterly

Change Process

  1. Propose event schema change (GitHub PR to this document)
  2. Review with domain team
  3. Update event version if breaking change
  4. Update consumers to handle new version
  5. Deploy consumers before deploying producers
  6. Monitor for errors

Document Status: ✅ Complete Related Documents: ARCHITECTURE_OVERVIEW.md, DATA_MODELS.md, API_CONTRACTS.md