Git Product home page Git Product logo

buy-a-ticket's Introduction

Buy a Ticket app

Requirements

Apps:

  • Docker
  • Kubernetes
  • Ingress-nginx controller (as load balancer service)
  • skaffold

Libraries/ Shared Code:

Shared code is just another git project which is added as git submodule and published as NPM public *@ngazicticketingapp/common Linke here

Change localhost to custom host ticketing.dev

Set your local routing to custom ticketing.dev (this is ingress requirement). The host file is on the path "C:\Windows\System32\drivers\etc" (Windows)

In Chrome type: thisisunsafe (to use http)

Dev / Production Prerequisites

Inside root directory, run:

kubectl create secret generic jwt-secret --from-literal=JWT_KEY=somesecretpasswordinkubernetes # to create secret JWT token signature in Kubernetes
kubectl create secret generic stripe-secret --from-literal=STRIPE_KEY=somesecretpasswordinkubernetes # to create secret Stripe token in Kubernetes, e.i. use "sk_test_51Kog8zFJPhsaxAKzeAakeguFNkjydu6iu2ReGl4JcSG5dZn1Z5Fzgu3AQ2VVBbxgSG5DChCuePiNrQr5pWQJqVMb00Pfb2DsiT" which is test implementation
kubectl get secrets # to check all the secrets
skaffold dev

Description

  • Users can list a ticket for an event (concert, sports) for sale
  • Other users can purchase this ticket
  • Any users can list tickets for sale and purchase tickets
  • When a user tries to purchase, the ticket is "locked" for 15 minutes. The user has 15 minutes to enter their payment info
  • While locked, no other user can purchase the ticket. After 15 minutes, the should "unlock"
  • Ticket prices can be edited if they are not locked

Services

We are creating a separate service to manage each type of resource:

  1. auth (everything related to user signup/signin/signout)
  2. tickets (ticket creation/editing. Knows whether a ticket can be updated)
  3. orders (order creation/editing)
  4. expiration (watches for orders to be created, cancels them after 15 minutes)
  5. payments (handles credit card payments. Cancels orders if payments fails, completes if payment succeeds)

Events

  1. UserCreated
  2. UserUpdated
  3. OrderCreated
  4. OrderCancelled
  5. OrderExpired
  6. TicketCreated
  7. TicketUpdated
  8. ChargeCreated

Common response Structure

  1. All error responses that we send out from any server should have this structure:
{
  errors: {
    message: string, field?:string
  }[]
}
  1. The response status should be accordingly to the error

The error model

We'll inherit this abstract class for all our custom errors:

abstract class CustomError extends Error {
  abstract statusCode: number;

  constructor(message: string) {
    super(message);

    Object.setPrototypeOf(this, CustomError.prototype);
  }

  abstract serializeErrors(): { message: string; field?: string }[];
}

Handling async errors

Use express-async-errors package

Sharing all services common secrets inside Kubernetes

I.e. create jwt signing key:

kubectl create secret generic jwt-secret --from-literal=JWT_KEY=jwt_signature_value

## checking the secrets
kubectl get secrets

CI/CD

This is example of CI/CD

Appendix

Steps to develop microservice with Kubernetes and skaffold

  1. Create package.json, install deps
  2. Write Dockerfile
  3. Create index.ts to run project
  4. Build image, push to docker hub
  5. Write k8s file for deployment, service
  6. Update skaffold.yaml to do file sync for the service
  7. Write k8s file for MongoDB Deployment and service

Switching between Kubernetes local and production (i.e. Digital Ocean ) cluster

kubectl config view
### Choose your config
kubectl config use-context <context name>

CI is done by Github actions for each microservice selectively,and for Infra folder. Also, test are run on creating pull request as well.

Note: do the final push of all images to docker hub for each service after the development is done!!!

buy-a-ticket's People

Contributors

ngazic avatar

Watchers

 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.