Giter Club home page Giter Club logo

kafka-fraud-detector's Introduction

Kafka Fraud Detector

Kafka Docker Images Python

This is the supporting repository for my blog post: Building A Streaming Fraud Detection System With Kafka And Python.

Install

This fraud detection system is fully containerised. You will need Docker and Docker Compose to run it.

You simply need to create a Docker network called kafka-network to enable communication between the Kafka cluster and the apps:

$ docker network create kafka-network

All set!

Quickstart

  • Spin up the local single-node Kafka cluster (will run in the background):
$ docker-compose -f docker-compose.kafka.yml up -d
  • Check the cluster is up and running (wait for "started" to show up):
$ docker-compose -f docker-compose.kafka.yml logs -f broker | grep "started"
  • Start the transaction generator and the fraud detector (will run in the background):
$ docker-compose up -d

Usage

Show a stream of transactions in the topic T (optionally add --from-beginning):

$ docker-compose -f docker-compose.kafka.yml exec broker kafka-console-consumer --bootstrap-server localhost:9092 --topic T

Topics:

  • queuing.transactions: raw generated transactions
  • streaming.transactions.legit: legit transactions
  • streaming.transactions.fraud: suspicious transactions

Example transaction message:

{"source": "yGfZ1Xa6k1r0", "target": "N5RvY7RO5sQF", "amount": 217.46, "currency": "EUR"}

Teardown

To stop the transaction generator and fraud detector:

$ docker-compose down

To stop the Kafka cluster (use down instead to also remove contents of the topics):

$ docker-compose -f docker-compose.kafka.yml stop

To remove the Docker network:

$ docker network rm kafka-network

kafka-fraud-detector's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

kafka-fraud-detector's Issues

Dockerfile question

Hi,

First off, thank you for the great tutorial!

I have a question regarding the Dockerfile for the generator and the detector

FROM python:3.6

WORKDIR /usr/app

ADD ./requirements.txt ./
RUN pip install -r requirements.txt
ADD ./ ./

CMD ["python", "app.py"]

Couldn't you delete ADD ./requirements.txt ./ and move ADD ./ ./ up before the Run Pip line since it adds all the necessary files anyway? If I'm correct, I can submit a PR if you'd like.

Also, the blog post source is not consistent with the repo source. See below

# Dockerfile
FROM python:3.7

WORKDIR /usr/app

ADD ./requirements ./
RUN pip install -r requirements.txt
ADD ./app.py ./

CMD ["python", "app.py"]

Actually the command line to watch the stream should be this one

docker exec kafkafrauddetector_broker_1 kafka-console-consumer --bootstrap-server localhost:9092 --topic streaming.transactions.legit

The kafkafrauddetector_broker_1 is the name of the containers start with image kafkafrauddetector_detector .

I am not very sure why the docker-compose not works.

Then I got the stream printed as

{"source": "uZxSDHD4wcE5", "target": "g0wgLDJftHBW", "amount": 150.45, "currency": "EUR"}
{"source": "3wiBuTZ9Sknw", "target": "r2UMsWnddfB4", "amount": 533.24, "currency": "EUR"}
{"source": "JgxFHAgwN8pj", "target": "YIEKjarfhMME", "amount": 273.84, "currency": "EUR"}
{"source": "UwpUOkML6rE0", "target": "lpth8JQQJYn3", "amount": 580.66, "currency": "EUR"}
{"source": "dqjbxgwsdJLV", "target": "JPmpzh2hiHzp", "amount": 152.41, "currency": "EUR"}
{"source": "tUb6sHBbbOnJ", "target": "wqyVub0ZnsuY", "amount": 91.31, "currency": "EUR"}
{"source": "1ljt52vUC2Aw", "target": "jHGOvGtbgW5E", "amount": 884.41, "currency": "EUR"}
{"source": "tpjFGUpeWE9y", "target": "rJ28GOX1OuRT", "amount": 874.21, "currency": "EUR"}
{"source": "vIhuz9ncvkev", "target": "1IiGlLtclgp8", "amount": 261.06, "currency": "EUR"}
{"source": "F7QziI9EksWS", "target": "jdz7KaaNbro1", "amount": 740.54, "currency": "EUR"}
{"source": "8PgQvfjGx7Ux", "target": "l6U6uHA9lp07", "amount": 502.15, "currency": "EUR"}
{"source": "EVqWKd9wRtjG", "target": "i3HHMtFfVmHK", "amount": 8.62, "currency": "EUR"}
{"source": "qreSXgRlSiDr", "target": "nVPkhU7gtcc9", "amount": 840.88, "currency": "EUR"}
{"source": "m6mmbKIBqEpI", "target": "010nHlF8WYj4", "amount": 282.72, "currency": "EUR"}

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.