Coder Social home page Coder Social logo

pushservice's Introduction

Kafka demo architecture

Overview

Simple, scalable web push service backend, written in node.js. The architecture is also simple, this application is consist of two microservices.

  1. Parser - Prepare & format push data for sending.
  2. Sender - Responsible for sending push to the user's device.

It can send push notifications to any VAPID supported browser.

Completely decoupled service, you can easily add several service instances or remove services that you don't need. It will be auto balanced after adding or removing an instance.

How it works

This application is based on Apache Kafka. The parser service will always listen for a push on raw-push topic and when it gets a push, it starts processing subscriber details from a MongoDB read stream. After preparing push with subscriber's data, it will send to another topic push, where sender service is listening. The sender will transfer pushes to subscriber's devices by using web-push protocol.

Enough talk, How to run this?

Step 1: Installation

git clone [email protected]:joynal/pushservice.git
cd pushservice
npm i
npm install -g pm2

Step 2: Create Kafka topics

  • create push with 200 partitions
  • create raw-push with 4 partitions

Step 3: Setup environment variables

Copy .env.example to .env and replace .env configurations.

Step 4: Generate dummy data

Generate site:

node seed/generateSite.js

Copy site id then generate push & subscribers:

node seed/seed/generatePush.js [siteId]
node seed/generateSubscribers.js [siteId] [number of subscribers]

Step 5: Server tweak

Increase your open file limits:

ulimit -n 1000000
ulimit -S 1000000

Step 6: Start services

parser:

node src/parser.js

sender:

node src/sender.json

Alternative pm2 way, it will create maximum instances.

parser:

pm2 start pm2/parser.json

sender:

pm2 start pm2/sender.json

Step 7: Send a push notification

node cmd/send.js [pushId]

Issues to work with

Some issue may arise when you try to send a large number of pushes(1 Million or more). Which is not related to this application; it depends on your OS and node.js configurations and number of sender servers. Under high load node.js drop connections, till 500k-600k push is ok without any issues(When I tested). Must increase your OS open file limits & maximize bandwidth if possible. An increasing number of sender servers can balance the load & will remove these errors.

Errors may encounter under high load:

  • Client network socket disconnected before secure TLS connection was established
  • Connect EADDRNOTAVAIL 108.177.111.95:443 - Local (10.128.0.5:0)
  • read ECONNRESET
  • socket hang up

Benchmarks

The service is tested with generated fake push subscriptions.

Kafka:

  • used cloudkarafka's BOUNCING BAT plan
  • raw-push - 4 partitions
  • push - 200 partitions.

Servers:

  • Google compute engine.
  • Parser - 1 server 4GB Memory, 2 core, first-generation - 2 parser instances, 1 used.
  • Sender - 8 servers 8GB Memory, 4 core, first-generation - 32 sender instances, all used.

1 Million push took:

  • 3min, 10sec - first time
  • 2min, 42sec - second time
  • 2min, 31sec - third time
  • 3min, 15sec - fourth time

Extras

All necessary server setup commands added on setup.sh file.

Need sponsors

If anyone can sponsor me servers for load testing, I will optimize it further and will add all the necessary resources.

License

This project is licensed under the MIT License - see the license.md file for details

Thanks

Cloudkarafka & Cloudclusters for providing a free trail.

pushservice's People

Contributors

joynal avatar

Stargazers

Ahsan Ullah avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.