Quick Start

Stream lets you build activity feeds at scale. The largest apps using Stream have over 100 million users. Stream Activity Feeds scales effectively while giving you more flexibility over the content shown in your feed.

Stream Feeds has two halves. Feed groups, ranking, permissions and push setup are configured on your backend with a server-side SDK, authenticated with your API secret. The code you ship to your users is a client SDK, and it connects with a token signed on that backend. Whichever half you are here for, this sidebar carries an overview of the other.

Start here

Getting started

For SDK-accurate examples generated from the OpenAPI spec, use the Stream snippets reference: TypeScript SDK - Feeds API. Replace node in the URL with the SDK language you want to inspect.

require 'getstream_ruby'

# Initialize the client
client = GetStreamRuby.manual(
  api_key: 'your_api_key',
  api_secret: 'your_api_secret'
)

# Create a feed (or get its data if exists)
feed_response = client.feeds.get_or_create_feed(
  'user',
  'john',
  GetStream::Generated::Models::GetOrCreateFeedRequest.new(user_id: 'john')
)

# Add activity
activity_request = GetStream::Generated::Models::AddActivityRequest.new(
  type: 'post',
  text: 'Hello, Stream Feeds!',
  user_id: 'john',
  feeds: ['user:john']
)

response = client.feeds.add_activity(activity_request)

Key concepts

Activities

Activities are the core content units in Stream Feeds. They can represent posts, photos, videos, polls, and any custom content type you define.

Feeds

Feeds are collections of activities. They can be personal feeds, timeline feeds, notification feeds, or custom feeds for your specific use case.

Real-time updates

Stream Feeds provides real-time updates through WebSocket connections, ensuring your app stays synchronized with the latest content.

Social features

Built-in support for reactions, comments, bookmarks, and polls makes it easy to build engaging social experiences.

Server-side vs client-side

Most API calls can be made client-side. Client-side API calls use the permission system. Server-side API calls have full access.

flowchart LR
  subgraph app[Your app]
    client[Client SDK]
  end
  subgraph backend[Your backend]
    server[Server-side SDK]
  end
  client <--> api[Stream API]
  server --> api
  server -. user token .-> client

Most apps will default to making API calls client-side. Engineers will often use server-side to do the following tasks:

  • Updating feed groups or feed views for ranking and aggregation
  • Syncing users
  • Returning tokens for authenticating users
  • Writing to feeds that do not belong to the current user (since the user does not have access client side to do this)

Common use cases

Social media feed

# Create a timeline feed
timeline_response = client.feeds.get_or_create_feed(
  'timeline',
  'john',
  GetStream::Generated::Models::GetOrCreateFeedRequest.new(user_id: 'john')
)

# Add a reaction to activity
reaction_request = GetStream::Generated::Models::AddReactionRequest.new(
  type: 'like',
  user_id: 'john'
)
reaction_response = client.feeds.add_reaction('activity_123', reaction_request)

# Add a comment to activity
comment_request = GetStream::Generated::Models::AddCommentRequest.new(
  comment: 'Great post!',
  object_id: 'activity_123',
  object_type: 'activity',
  user_id: 'john'
)
comment_response = client.feeds.add_comment(comment_request)

# Add a reaction to comment
comment_reaction_request = GetStream::Generated::Models::AddCommentReactionRequest.new(
  type: 'love',
  user_id: 'john'
)
comment_reaction_response = client.feeds.add_comment_reaction(
  comment_response.comment.id,
  comment_reaction_request
)

Notification feed

# Create a notification feed
notifications_response = client.feeds.get_or_create_feed(
  'notification',
  'john',
  GetStream::Generated::Models::GetOrCreateFeedRequest.new(user_id: 'john')
)

# Mark notifications as read
mark_request = GetStream::Generated::Models::MarkActivityRequest.new(
  mark_all_read: true
)
client.feeds.mark_activity('notification', 'john', mark_request)

Polls

# Create a poll
poll_request = GetStream::Generated::Models::CreatePollRequest.new(
  name: 'What is your favorite color?',
  user_id: 'john',
  options: [
    GetStream::Generated::Models::PollOptionInput.new(text: 'Red'),
    GetStream::Generated::Models::PollOptionInput.new(text: 'Blue'),
    GetStream::Generated::Models::PollOptionInput.new(text: 'Green')
  ]
)
poll_response = client.common.create_poll(poll_request)

# Attach poll to an activity
activity_request = GetStream::Generated::Models::AddActivityRequest.new(
  type: 'poll',
  text: 'What is your favorite color?',
  poll_id: poll_response.poll.id,
  user_id: 'john',
  feeds: ['user:john']
)
activity_response = client.feeds.add_activity(activity_request)

# Cast a vote
vote_request = GetStream::Generated::Models::CastPollVoteRequest.new(
  vote: GetStream::Generated::Models::VoteData.new(
    option_id: poll_response.poll.options.first.id
  ),
  user_id: 'john'
)
vote_response = client.feeds.cast_poll_vote(
  activity_response.activity.id,
  poll_response.poll.id,
  vote_request
)

Advanced features

Custom activity types

Create custom activity types to represent your app's specific content:

# Add custom activity with custom fields
workout_activity = GetStream::Generated::Models::AddActivityRequest.new(
  type: 'workout',
  text: 'Just finished my run',
  user_id: 'john',
  feeds: ['user:john'],
  custom: {
    distance: 5.2,
    duration: 1800,
    calories: 450
  }
)

response = client.feeds.add_activity(workout_activity)

Real-time updates with the state layer

Only for client-side SDKs

JavaScript
const feed = client.feed("user", "john");
// Subscribe to WebSocket events for state updates
await feed.getOrCreate({ watch: true });
feed.state.subscribe((state) => {
  // Called everytime the state changes
  console.log(state);
});

// or if you only want to observe part of the state
feed.state.subscribeWithSelector(
  (state) => ({
    activities: state.activities,
  }),
  (state, prevState) => {
    console.log(state.activities, prevState?.activities);
  },
);

// Current state
console.log(feed.state.getLatestValue());

What's next