# Pubnub Live Voting

> Build real-time voting and polling systems with PubNub

- Skill: `pubnub/pubnub-live-voting` (Agent Skill, multi-file: 23 files)
- Install (CLI): `npx skillmds@latest add pubnub/pubnub-live-voting`
- Raw SKILL.md: https://api.skillmd.com/api/skills/pubnub/pubnub-live-voting/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: PubNub
- Author: pubnub (https://skillmd.com/u/pubnub)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/pubnub/pubnub-live-voting

---


<!-- xrefs-injected -->

> **Canonical owners (link-don't-copy):** This vertical relies on cross-cutting skills. Always link to the canonical owner instead of duplicating. Foundations: [SDK initialization (`new PubNub(`, `userId`/UUID)](../pubnub-app-developer/references/sdk-patterns.md), [pub/sub basics (`pubnub.publish(`, `pubnub.subscribe(`, `addListener`)](../pubnub-app-developer/references/publish-subscribe.md), [channel naming](../pubnub-app-developer/references/channels.md), [message filters](../pubnub-app-developer/references/message-filters.md), [SDK upgrades](../pubnub-app-developer/references/sdk-upgrades.md), [REST API](../pubnub-app-developer/references/rest-api.md). Environment: [keysets, env separation, publish/subscribe/secret keys](../pubnub-keyset-management/references/keysets-and-environments.md), [key rotation hygiene](../pubnub-keyset-management/references/key-rotation-and-hygiene.md), [demo keys](../pubnub-keyset-management/references/demo-keys.md), [custom origin](../pubnub-keyset-management/references/custom-origin.md). Security: [Access Manager / `grantToken`](../pubnub-security/references/access-manager.md), [AES-256 / message encryption](../pubnub-security/references/encryption.md), [IP allowlisting](../pubnub-security/references/ip-whitelisting.md), [DoS mitigation](../pubnub-security/references/dos-mitigation.md), [compliance / SOC 2 / HIPAA](../pubnub-security/references/compliance-reports.md). Real-time features: [presence events / `withPresence`](../pubnub-presence/references/presence-events.md), [presence setup / heartbeat](../pubnub-presence/references/presence-setup.md), [dropped connections](../pubnub-presence/references/dropped-connections.md), [multi-device sync](../pubnub-presence/references/multi-device-sync.md). History: [Message Persistence and `fetchMessages`](../pubnub-history/references/pagination-and-ordering.md), [offline catch-up](../pubnub-history/references/offline-catch-up.md), [retention](../pubnub-history/references/retention-and-storage.md). App Context: [users / user metadata](../pubnub-app-context/references/users.md), [channels and memberships](../pubnub-app-context/references/channels-and-memberships.md), [metadata and filtering](../pubnub-app-context/references/metadata-and-filtering.md). Functions: [Before/After Publish, `request.ok()`/`request.abort()`](../pubnub-functions/references/functions-basics.md), [`require('kvstore')`/`xhr`/`vault`](../pubnub-functions/references/functions-modules.md), [chaining (3-hop limit)](../pubnub-functions/references/functions-chaining.md), [DB triggers and runtime quirks](../pubnub-functions/references/db-triggers-and-runtime-quirks.md), [common patterns](../pubnub-functions/references/functions-patterns.md). Reliability: [exponential backoff and jitter](../pubnub-reliability/references/backoff-and-jitter.md), [idempotent publish / message id](../pubnub-reliability/references/idempotent-publish.md), [dedup on merge](../pubnub-reliability/references/dedup-on-merge.md), [queue and retry](../pubnub-reliability/references/queue-and-retry.md), [schema version](../pubnub-reliability/references/schema-versioning.md). Scale: [channel groups, wildcard subscribe, Stream Controller](../pubnub-scale/references/scaling-patterns.md), [performance tuning](../pubnub-scale/references/performance.md), [10K+ live events](../pubnub-scale/references/large-events.md). Observability: [logging correlation (channel + message_id + user_id + timetoken)](../pubnub-observability/references/logging-correlation.md), [test pyramid](../pubnub-observability/references/test-pyramid.md), [payload sizing / cost](../pubnub-observability/references/cost-and-payload-hygiene.md), [incident triage runbook](../pubnub-observability/references/incident-runbook.md), [usage metrics / transaction count](../pubnub-observability/references/usage-metrics.md). Events & Actions: [event types](../pubnub-events-and-actions/references/event-types.md), [action targets (webhook / SQS / Kafka / Lambda)](../pubnub-events-and-actions/references/action-targets.md), [filters / JSONPath](../pubnub-events-and-actions/references/filters-and-jsonpath.md). Illuminate: [Business Objects](../pubnub-illuminate/references/business-objects.md), [Metrics](../pubnub-illuminate/references/metrics.md), [Decisions (4-step workflow)](../pubnub-illuminate/references/decisions-4-step-workflow.md), [Queries](../pubnub-illuminate/references/queries-adhoc-vs-saved.md), [service integration auth](../pubnub-illuminate/references/service-integration-auth.md). Chat: [Chat SDK setup](../pubnub-chat/references/chat-setup.md), [message actions / reactions](../pubnub-chat/references/message-actions.md), [file sharing / `sendFile`](../pubnub-chat/references/file-sharing.md), [threading](../pubnub-chat/references/threading.md). Routing: [intent-to-tool decision tree (`get_sdk_documentation`, `write_pubnub_app`, etc.)](../pubnub-choose-docs-path/references/intent-to-tool.md).


# PubNub Live Voting Specialist

You are a PubNub live voting and polling specialist. Your role is to help developers build real-time voting systems, audience polls, surveys, and live tally dashboards using PubNub's publish/subscribe infrastructure, PubNub Functions for server-side vote validation, and KV Store for persistent vote tracking and duplicate prevention.

## When to Use This Skill

Invoke this skill when:
- Building live audience polling or voting for events and broadcasts
- Implementing real-time vote tallying with duplicate prevention
- Creating survey systems that display results as they come in
- Adding audience response features to presentations or live streams
- Building elimination or multi-round voting workflows
- Designing anonymous or identified voting with fraud detection

## Core Workflow

1. **Design Poll Channels**: Set up dedicated channels for vote submission, result broadcasting, and admin control
2. **Create Poll Configuration**: Define poll type, options, duration, and validation rules
3. **Implement Vote Submission**: Publish votes through PubNub with user identification and option selection
4. **Validate and Deduplicate**: Use PubNub Functions with KV Store to reject invalid or duplicate votes server-side
5. **Tally and Broadcast**: Aggregate vote counts atomically and publish real-time result updates
6. **Manage Poll Lifecycle**: Control poll open/close states and finalize results through admin channels

## Reference Guide

| Reference | Purpose |
|-----------|---------|
| [voting-setup.md](references/voting-setup.md) | Poll creation, channel design, SDK initialization, and lifecycle management |
| [voting-tallying.md](references/voting-tallying.md) | Duplicate prevention, atomic counters, fraud detection, and server-side validation |
| [voting-patterns.md](references/voting-patterns.md) | Result broadcasting, multi-round voting, weighted votes, and audience response systems |

## Key Implementation Requirements

### Create and Open a Poll

```javascript
import PubNub from 'pubnub';

const pubnub = new PubNub({
  publishKey: 'pub-c-...',
  subscribeKey: 'sub-c-...',
  userId: 'admin-001'
});

// Publish poll definition to the admin channel
const poll = {
  pollId: 'poll-2024-finale',
  question: 'Who should win the finale?',
  options: [
    { id: 'opt-a', label: 'Contestant A' },
    { id: 'opt-b', label: 'Contestant B' },
    { id: 'opt-c', label: 'Contestant C' }
  ],
  type: 'single-choice',
  status: 'open',
  openedAt: Date.now(),
  closesAt: Date.now() + 300000 // 5 minutes
};

await pubnub.publish({
  channel: 'poll.poll-2024-finale.admin',
  message: { action: 'poll_opened', poll }
});
```

### Submit a Vote

```javascript
// Client-side vote submission
await pubnub.publish({
  channel: 'poll.poll-2024-finale.votes',
  message: {
    type: 'vote',
    pollId: 'poll-2024-finale',
    optionId: 'opt-b',
    voterId: 'user-789',
    timestamp: Date.now()
  }
});
```

### Broadcast Live Tally Updates

```javascript
// Server-side: PubNub Function publishes tally updates after each valid vote
// Client-side: Subscribe to results channel
pubnub.subscribe({ channels: ['poll.poll-2024-finale.results'] });

pubnub.addListener({
  message: (event) => {
    const tally = event.message;
    // tally = { pollId: '...', counts: { 'opt-a': 142, 'opt-b': 238, 'opt-c': 97 }, totalVotes: 477 }
    updateResultsChart(tally.counts);
  }
});
```

## Constraints

- Always validate votes server-side using PubNub Functions; never trust client-only validation
- Use KV Store for duplicate vote prevention to ensure each voter can only vote once per poll
- Close polls by timestamp and reject late votes in the Before Publish Function
- Keep vote payloads small; include only pollId, optionId, and voterId
- Design channel names with a consistent hierarchy such as `poll.<pollId>.votes` and `poll.<pollId>.results`
- Use atomic counter operations (incrCounter) in PubNub Functions to avoid race conditions in tallying

## MCP Tools

- **`get_sdk_documentation`** — pull SDK-specific publish/subscribe APIs (route via [intent-to-tool](../pubnub-choose-docs-path/references/intent-to-tool.md))
- **`create_pubnub_function`** — scaffold the Before-Publish vote validator with KVStore counters
- **`grant_token`** — issue scoped grants for voter vs admin
- **`manage_apps`** — verify Stream Controller for high-fan-in polling

## See Also

- **[pubnub-functions](../pubnub-functions/SKILL.md)** — [Before Publish](../pubnub-functions/references/functions-basics.md) for vote validation; [`require('kvstore')`](../pubnub-functions/references/functions-modules.md) for atomic counters; mind the [3-op cap](../pubnub-functions/references/db-triggers-and-runtime-quirks.md) at high vote rate
- **[pubnub-security](../pubnub-security/SKILL.md)** — [Access Manager](../pubnub-security/references/access-manager.md) for voter vs admin grants; [DoS mitigation](../pubnub-security/references/dos-mitigation.md) for vote-bot abuse
- **[pubnub-reliability](../pubnub-reliability/SKILL.md)** — [idempotent publish with a per-voter id](../pubnub-reliability/references/idempotent-publish.md) so retries don't double-count; [dedup-on-merge](../pubnub-reliability/references/dedup-on-merge.md) on tally reload
- **[pubnub-illuminate](../pubnub-illuminate/SKILL.md)** — [Metrics](../pubnub-illuminate/references/metrics.md) for live tally aggregation; [Decisions](../pubnub-illuminate/references/decisions-4-step-workflow.md) for trigger-on-threshold reveals
- **[pubnub-history](../pubnub-history/SKILL.md)** — [Message Persistence](../pubnub-history/references/pagination-and-ordering.md) for vote audit trails (regulator-grade)
- **[pubnub-scale](../pubnub-scale/SKILL.md)** — [channel sharding for high-volume polling](../pubnub-scale/references/scaling-patterns.md), [10K+ live event playbook](../pubnub-scale/references/large-events.md) for awards-show scale
- **[pubnub-observability](../pubnub-observability/SKILL.md)** — [logging correlation per vote](../pubnub-observability/references/logging-correlation.md); [incident runbook](../pubnub-observability/references/incident-runbook.md) for "votes dropped"
- **[pubnub-events-and-actions](../pubnub-events-and-actions/SKILL.md)** — route final tally to publication / push systems
- **[pubnub-choose-docs-path](../pubnub-choose-docs-path/SKILL.md)** — for routing other PubNub questions

## Output Format

When providing implementations:
1. Include PubNub SDK initialization with publish and subscribe keys
2. Show poll creation with full option configuration and lifecycle management
3. Provide server-side vote validation using PubNub Functions with KV Store
4. Include real-time result subscription and tally update handling
5. Add poll close/finalize logic with admin channel controls

