Polka Payments is my attempt to build a peer-to-peer payments application, similar to Zelle. Instead of having an internal ledger like Venmo, Polka wires payments between bank accounts from different banks. Polka benefits consumers with fast and free inter-bank cash transfers, but it also benefits banks, simplifying settlements by acting as a clearing house.
Polka Payments comprises 6 essential components:
- A load balancer that distributes a high volume of transactions evenly among servers.
- An array of servers that handle requests, submitting data to the database and cache.
- A cache registering changes in account balances efficiently.
- A settler that requests a snapshot of all balances from the cache and refers it to both the client and the MongoDB database
- A PostgreSQL database storing data from each payment and net balances owed to individual banks and accounts.
- A MongoDB database storing balance snapshots
Additionally, since Polka doesn't have any clients (yet!), the project includes a load generator to load test the application.
Polka Payments requires no specific installation, though it does require installing certain Go dependencies. Running a database requires connecting to a PostgreSQL server and a MongoDB server. Running scripts on Linux may require either tmux or multitail. Lastly, using docker requires both Docker and docker-compose.
Polka Payments' components require environmental variables. These can be set up in the envs directory.
Polka Payments requires two databases, one with running PostgreSQL and the other running MongoDB, both configured with a dedicated user. With Docker, setting up your own databases is unnecessary, as Docker automatically runs isolated PostgreSQL and MongoDB containers. Without Docker, the databases must be configured from scratch. For an example of the required login information, check out envs/postgres.env and envs/mongo.env. For the schema, run setup.sql to create the required tables in the PostgreSQL database.
Polka Payments was written on a 64-bit Ubuntu 20.04 LTS OS using Go 1.17. The project uses a few external dependencies, most importantly pgx, a database driver for PostgreSQL.
To download all go dependencies, run from the project's root directory:
go get
Polka payments can run on any operating system supported by Docker or Go and PostgreSQL. It is best run with Docker. Without Docker, it is best run on a Linux distribution that supports Bash. It can nevertheless run on WindowsOS and MacOS without Docker.
Running Polka is easy with Docker. To start all services, run
docker-compose up
However, this will only run one processor server. To run multiple, run
docker-compose up --scale processor=<num>
where num is the number of processor servers.
To shut down the application, run
docker-compose down
To set up all binaries and a given number of processor servers, run
make prep n=$num
where $num is the number of processor servers.
To run the application and view streams of logs in tmux windows and panes, run
make stmux
To run the application and record logs in dedicated log.txt files, run
make stlog
Of note, multitail must be installed in order to view multiple logs at once in the same terminal window.
To shut down the application, run
make clean
To load test the application, run from the generator directory
make spam w=<workers> t=<transactions>
where workers is the number of maximum ongoing requests in any given moment, and transactions is the number of randomly generated transactions (as in payments) that are sent.
To get a snapshot of all balances stored in the cache, run
make getsnap
To then approve the snapshot and settle all balances, run
make settle
Polka Payments is licensed under the MIT Licence Copyright (c) 2022.
See the LICENSE for information on the history of this software, terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.
All trademarks referenced herein are property of their respective holders.