A microservice architecture that provides services for buyers and sellers of tickets for sports, concerts, theater and other live entertainment events.
- Production grade authentication service
- Sellers can list their tickets
- Sellers can update the price of the listed ticket
- Buyers are buy tickets
- Buyers will have a 15 minutes window to buy a ticket
- During that 15 minutes window no one can buy the ticket
- Handles the case when buyer buy the ticket and seller at the same time increases the price of the ticket
- Production grade payment service
Here common refers to a npm custom build library by us, which will be shared with all the services
Next.js
Node.js
Express.js
Mongodb
Redis
NATS
Stripe.js
Typescript
auth
: Everything related to user signup/signin/signouttickets
: Tickets creation/editing. Knows whether a ticket can be updatedorders
: Order creation/editingexpiration
: Watches for order to be created, cancels them after 15 minutespayments
: Handles credit card payments. Cancels order if payments fails, completes if payment succeeds
Auth
Route | Method | Body | Purpose |
---|---|---|---|
api/users/signup | POST | {email: string, password: string} | Signup for an account |
api/users/signin | POST | {email: string, password: string} | Signin to an existing account |
api/users/signout | POST | {} | Signout of an account |
api/users/currentuser | GET | - | Return info about the user |
-
User
Name Type email string password string -
Ticket
Name Type title string price number userId Ref to User orderId Ref to Order -
Order
Name Type userId Ref to User status Created, Cancelled, Awaiting payment, Completed ticketId Ref to Ticket expiresAt Date -
Charge
Name Type orderId Ref to Order status Created, Failed, Completed amount number stripeId string stripeRefundId string
UserCreated
UserUpdated
OrderCreated
OrderCancelled
OrderExpired
TicketCreated
TicketUpdated
ChargeCreated
- we will make two classes
RequestValidationError
andDatabaseConnectionError
which will extend to theError
class and so that they can add custom features to theError
class like reason of the error and message to show regarding the error - inside the
error-handler
middleware we will check if it is invoked due to theRequestValidationError
orDatabaseConnectionError
, and based on the error type it will send custom messages to the client
- All error response that we send out from our server will have this structure
{
errors: {
message: string,
field?: string
}[]
}
- All the error classes like
RequestValidationError
andDatabaseConnectionError
should contain astatusCode
variable and aserializeErrors
method. - To ensure all error classes stick to the rule we will make a CustomError Abstract Class
NOTE: on abstract class
- cannot be instantiated
- used to setup requirements for subclasses
- when we compile TS to JS, we end up with a class definition in JS from abstract class in TS unlike an interface as it does not exist in JS
Mongoose User Model
represents the entire collection of usersMongoose User Document
represents one single user
- We will be using JWT with cookies for our auth mechanism
- Because we're using
Next.js
, we're conducting server-side rendering, which means that if we want the client's initial request to include a JWT token, we'll have to rely on cookies
- In our Kubernetes cluster, we build an object called
secret
that contains multiple key-value combinations and is shared across all pods through environment variables.
- Creating a secret object (imperative)
kubectl create secret generic jwt-secret --from-literal=jwt=asdf