Coder Social home page Coder Social logo

amirguterman / event-processing-system Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 43 KB

This project consists of a server that receives events from a client, a client that sends events to the server, and a data processor that reads the events and updates a database accordingly.

License: MIT License

JavaScript 100.00%

event-processing-system's Introduction

Event Processing System

This is a Node.js application that consists of a server that receives events from a client and a data processor that reads the events and updates a database accordingly.

Setup & Running

  1. Clone the repository to your local machine.

    git clone https://github.com/amirguterman/event-processing-system.git
  2. Navigate to the project directory.

    cd event-processing-system
  3. Install the necessary dependencies by running:

    npm install
  4. Setup the database by running the SQL commands located in the provided SQL file.

    psql -h localhost -U postgres -d postgres -f create_table.sql

    Note: The password for the postgres user is password1!. You may need to input this password during the execution of the above command.

  5. Update the database connection configurations in server.js, client.js and data_processor.js if needed.

  6. Start the server

    node server.js
  7. Run the client

    node client.js

    Note: The client script is not a long-running process. It reads the events from the events.jsonl file and sends each event to the server, then exits.

  8. Run the data processor

    node data_processor.js

    Note: The data processor script is not a long-running process. It reads the events from the server-events.jsonl file, updates the user revenue data in the database, then exits.

The application will now be running, with the server accepting events at the /liveEvent endpoint, the client reading and sending events to the server, and the data processor updating the user revenue data in the database.

How the System Works

Server

The server, implemented in Node.js, listens to incoming POST requests at the /liveEvent endpoint. Upon receiving an event, the server logs the event data to a server-events.jsonl file. The server also provides a GET endpoint, /userEvents/:userId, which fetches the revenue for a specific user from the PostgreSQL database.

Client

The client module is responsible for sending events to the server. It reads the events from the events.jsonl file and sends each event to the server, then exits.

Data Processor

The data processor is responsible for processing the logged events and updating the user revenue data in the PostgreSQL database accordingly. It reads the events from the server-events.jsonl file, calculates the revenue changes for each user, updates the database, then exits.

Event Format

The events.jsonl file used by the client to send events to the server should be in the following format:

{"userId": "user1", "name": "add_revenue", "value": 100}
{"userId": "user1", "name": "subtract_revenue", "value": 50}
{"userId": "user2", "name": "add_revenue", "value": 200}

Each line is a JSON object representing an event, where:

"userId" is the ID of the user. "name" is the type of event. For this system, the event type can be either "add_revenue" or "subtract_revenue". "value" is the amount of revenue to be added to or subtracted from the user's total.

Events are separated by newlines (hence the .jsonl extension, indicating the file contains JSON Lines text).

event-processing-system's People

Contributors

amirguterman avatar

Watchers

 avatar  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.