---
title: Real-time Notifications
description: Build real-time notification systems with NoLag.
---

# Real-time Notifications

Build instant notification systems that reach users in real-time.

## Overview

NoLag makes it easy to deliver notifications instantly to users across all their devices. This guide covers setting up a notification system with user-specific channels.

## Client Setup

```typescript [TypeScript]
import { NoLag } from '@nolag/js-sdk'

const client = NoLag('your_access_token')
await client.connect()

// Subscribe to user-specific notifications
const userRoom = client.setApp('my-app').setRoom(`user-${userId}`)
userRoom.subscribe('notifications')

// Handle incoming notifications
userRoom.on('notifications', (notification) => {
  showNotification({
    title: notification.title,
    body: notification.body,
    icon: notification.icon,
    action: notification.action
  })
})
```
```python [Python]
from nolag import NoLag

client = NoLag('your_access_token')
await client.connect()

# Subscribe to user-specific notifications
user_room = client.set_app('my-app').set_room(f'user-{user_id}')
await user_room.subscribe('notifications')

# Handle incoming notifications
def on_notification(notification, meta):
    show_notification({
        'title': notification['title'],
        'body': notification['body'],
        'icon': notification['icon'],
        'action': notification['action']
    })

user_room.on('notifications', on_notification)
```
```go [Go]
package main

import (
    "fmt"

    nolag "github.com/NoLagApp/nolag-go"
)

func main() {
    client := nolag.New("your_access_token")
    client.Connect()

    // Subscribe to user-specific notifications
    userRoom := client.SetApp("my-app").SetRoom(fmt.Sprintf("user-%s", userID))
    // Subscribe with handler
    userRoom.Subscribe("notifications", func(data any, meta nolag.MessageMeta) {
        notification, _ := data.(map[string]any)
        showNotification(Notification{
            Title:  notification["title"].(string),
            Body:   notification["body"].(string),
            Icon:   notification["icon"].(string),
            Action: notification["action"].(string),
        })
    })
}
```

## Sending Notifications (Server)

```typescript [TypeScript]
import { NoLag } from '@nolag/js-sdk'

// Server-side: Connect and send notification to a user
const client = NoLag('your_server_access_token')
await client.connect()

const userRoom = client.setApp('my-app').setRoom('user-123')

userRoom.emit('notifications', {
  title: 'New Message',
  body: 'You have a new message from Alice',
  icon: 'message',
  action: '/messages/456'
})
```
```python [Python]
from nolag import NoLag

# Server-side: Connect and send notification to a user
client = NoLag('your_server_access_token')
await client.connect()

user_room = client.set_app('my-app').set_room('user-123')

await user_room.emit('notifications', {
    'title': 'New Message',
    'body': 'You have a new message from Alice',
    'icon': 'message',
    'action': '/messages/456'
})
```
```go [Go]
package main

import nolag "github.com/NoLagApp/nolag-go"

func main() {
    // Server-side: Connect and send notification to a user
    client := nolag.New("your_server_access_token")
    client.Connect()

    userRoom := client.SetApp("my-app").SetRoom("user-123")

    userRoom.Emit("notifications", map[string]any{
        "title":  "New Message",
        "body":   "You have a new message from Alice",
        "icon":   "message",
        "action": "/messages/456",
    })
}
```

## Notification Types

- **User notifications** - Personal notifications for a specific user
- **Broadcast notifications** - Announcements to all users
- **Group notifications** - Messages to specific user groups

## Best Practices

- Use user-specific rooms for private notifications
- Include action URLs for clickable notifications
- Consider notification preferences and quiet hours
- Use per-topic trigger webhooks to also send push notifications for offline users

## Next Steps

- [Webhooks for push notifications](/docs/concepts/webhooks)
- [Access Control](/docs/concepts/acl)
