PubNub Sentiment Machine: Real-time Tweet Analysis

0 MIN READ • Oct 23, 2018

People tweet a lot. And lots of people tweet about things they feel passionately about. It's easy to sift through a Twitter feed to look at how one person is feeling about a subject. But what about how everyone feels about a subject? That's a little harder to do.

At PubNub, we sought out the best way to do this analysis at the scale of Twitter. In other words, we wanted to consume the Twitter firehose, filter tweets by subject, analyze the sentiment (emotion), and visualize it on a real-time dashboard.

That’s exactly what we did with our Sentiment Analysis Machine. And the first thing we want to measure is the 2018 Midterms.

To test our machine, we chose to analyze the most polarizing upcoming event we could think of – the 2018 Midterms. The machine tracks dozens of keywords like Midterms, #election, redwave, bluewave, Cruz, Beto, and gauges each Tweet on a scale of 😠to 😁.

How Does It Work?

Sentiment-Machine-Diagram

The application itself is truly real-time, and all processing and analysis, from firehose to dashboard, takes under a second. All messaging runs through PubNub.

  • The PubNub Twitter Firehose pipes in 50 Tweets per second, which are filtered by keywords.
  • Tweets that match one of our selected keywords are processed through the Amazon Comprehend Block, which serverlessly gauges the sentiment of the Tweet.
  • Results are sent in real time to the live-visualization dashboard, powered by Initial State.

Want to check out the code? The full GitHub repo is available here.

Latest blog posts

AI
Oct 7, 2026

Why MCP Alone Isn’t Enough for AI-Assisted Real-Time Development

Discover why Model Context Protocol (MCP) alone isn't enough for building production-ready real-time apps, and how combining MCP with engineering guidance (PubNub Skills) ensures robust architecture.
Ginni Kakkar
Ginni Kakkar
Sports Media Engagement
Oct 1, 2026

The ultimate guide to fandom engagement in 2026

Learn the value of fandom engagement platforms and how brands monetize direct-to-consumer proximity, real-time messaging, and tiered subscriptions.
Daryl Pereira
Daryl Pereira
AI
Sep 30, 2026

AI Coding One Year Later: A Product Manager's Lessons

Product manager Cres Hay looks back on a year of AI coding: faster prototypes, narrower scope, and why human judgment still decides what is worth building.
Cres Hay
Cres Hay