Agenda
• Scope Definition
• Architecture principles and guidelines
• Domain Driven Design (DDD) Model
• Solution Architecture
• Detail Design
• Technical Work Flow (Sequence flow)
• Technology Stack – Recommendation
• Deployment Architecture
Scope
To design a Cinema Booking System
• The site is used by consumers to book movie tickets.
• Given a city, there are several theatres available.
• Each theatre may have multiple screens.
• Each screen may play multiple shows, with a different
movie per show.
• Each theatre may have a different seating arrangement.
• When a user enters the site, he may search by a theatre
or movie.
• Based on the search results, user selects and books a
ticket.
• Each ticket may reserve up to 6 seats.
• Booking must include a confirmed online payment.
• On booking, user is notified via an SMS and email.
Architecture principles and guidelines
Design Principle Description Usecase
Service
replication
Each service need to replicate, typically
either Vertically or Horizontally.
The most frequently used functionality is the Search
functionality for the entire website. The service needs to
replicate either Vertically or Horizontally as the quantum
of search requests increases. Kubernetes provide a great
way to replicate services easily using Replication
Controller. Also with Autoscaling enabled in AWS would
enable the container to scale vertically and horizontally.
Service
discovery
Multiple services might be collaborating to
provide an application’s functionality.
Booking service needs data from Movie, Screen, Theatre
etc.. Related services to initiate the ticket booking for the
user. This requires the API gateway to identify and obtain
the necessary handle . The API Gateway uses the Service
Registry to perform service discovery. Netflix Eureka
provides a good option for Service discovery. Netflix
Eureka achieves high availability by running one or more
Eureka servers in each Amazon EC2 availability zone.
Resiliency High Availability and Disaster recovery For HA and DR its very important for services to
automatically take corrective action and ensure the user
experience is not impacted. For example, Netflix’s Hystrix
provide an implementation of Circuit Breaker pattern to
deal with software resiliency.
Consistency To maintain consistency when performing
transactions
Use SQL where transactions should follow consistency and
transaction level ACID properties need to be taken care off.
Like ticket booking, updating the status from available to
blocked to booked since it requires db transactions etc.
AWS RDS provides a great facility for data replication and
consistency in AWS.
Architecture principles and guidelines
Design Principle Description Usecase
Availability To maintain high availability meeting 99.98%
uptime SLAs.
Use NoSQL while performing searches and mainly on data
retrieval wherever High Availability needs to be achieved.
Casandra is recommended.
Elastic Search Seamless search for small and big data sets
(Analytics)
Excellent choice to perform fast search for large datasets
with high availability requirements. As the search load
increases, this ElasticSearch container can be autoscaled.
Kafka Queue Queuing of Events for Notifications and
Delivery
Booking and Notifications flows has async operations which
could be handled via queues. While booking tickets, there is
a need to notify external systems. Queue is populated with
appropriate messages/events along with metadata and the
receiver service picks up the events and delivers to the
External system. On Payment confirmation, there is a need
to deliver SMS/Email to customers and as well notify back to
the external theatre systems.
Service
monitoring
Centralised logging easily identifies server
problems or applications.
Zipkin to gather timing data needed to troubleshoot latency
problems in microservice, ELK (Elastic Search, LogStash,
Kibana) for searching, analyzing, and visualizing log data in
real-time.
Allows you to identify any issues spanning multiple servers
by correlating all the logs within a specified time frame. An
open source tool which collects and stores logs, Logstash
indexes the logs, while Kibana , a web interface, is used to
view and search the logs already indexed.
Domain Driven Design
Solution Architecture
API Gateway
Service
Service
NoSQL
Message
Queue
Web / Mobile Client
HTTP, Web SocketJSON, JWT Notifications
HTTP
Service
Service
SQL
HTTP
Service
Publish
Subscribe
Client Side
Server Side
NoSQL
External Systems
Proprietary Formats
Security and Access
Mgmt
Service
Registry
Rest API
Rest
API
All services are exposed as REST.
Sample shown here.
No-SQL
Use NoSQL while performing
searches and mainly on data
retrieval. Wherever High
Availability needs to be achieved.
SQL
Use SQL where transactions
should follow consistency and
transaction level ACID properties
need to be taken care off. Like
ticket booking, updating the status
from available to blocked to
booked since it requires db
transactions etc.
JWT
Access
Token
Rule Engine
(Optional)
Payment Gateway API
(CCAvenue/Razorpay
/PayPal etc..)
Theatre External
System
SMS/eMail Gateway
API
Elastic Search
Engine
Detail Design
API Gateway Web
Container
API Web Gateway -
MS
Admin Container
Location- MS Theatre - MS
Movie - MS
SeatStucture - MS
ReservationStatus - MS
Screens - MS
Customer Container
Customer - MS
Payment Container
PaymentGtwy - MS
External System Container
External Gateway - MS
API & Auth Layer Micro Service Layer Admin & System
Monitoring Layer
Database Layer
Eureka
Eureka - MS
Zipkin
Zipkiin - MS
ELK
Elastic Search
Logstash
Kibana
Rule Engine (Optional)
Rule Engine - MS
No-SQL DB
Cluster
Kafka Container
Kafka
Queue
API Gateway Mobile
Container
API Mobile
Gateway - MS
Auth Container
Authentication
Server
(OAuth2/OpenIDCon
nect Server)
Notification
eMail - MS
Booking Container
SeatSeleced - MS
Booking - MS
SMS - MS
Analytics Container (Optional)
R Related - MS
Search- MS
SQL DB Cluster
NOTE: All services are
configured and managed
via Kubernetes. Zipkin
and ELK monitors their
logs and state transition.
Enabling Search with Elastic
Search
API Gateway
Location
Microservice
Location
Store
Movie
Microservice Movie Store
5. Lookup
Movies,
Theatres based
on Location
5a. Lookup
Movies
4. Lookup
Screen Details
4a. Return
Screen
details
6. JSON
representation of
movies, screens
and theatres
Theatre
Microservice
Theatre
Store
2. Lookup
Theatres for a
location
2a. Return
Location details
3. Lookup
Theatre details
3a. Return
Theatre
details
7. Push the JSON
representation of
movies, screens and
theatres to the
ElasticSearch Cluster
Screen
Microservice Screen Store
2b. Return JSON
representation of
Location
3b. Return JSON
Representation of
Theatre
4b. Return JSON
representation of
Screen
ES
Spring Batch Framework – To trigger
loading of JSON documents to Elastic
Search Cluster (Spring Container)
JavaScheduler
Spring Application Context
Customer Search Flow
XContentBuil
derService
Guest User
Visits
booking
site
Search request
submitted
2. To convert JSON to Java
Object
API
Gateway
ES Elastic Search Container
Jackson ->
ObjectMapper
1. JSON representation
of movies, screens and
theatres is pushed to
XContentBuilderService
3. prepareIndex() - this
makes arbitary JSON
document Searchable.
prepareIndex
SearchService QueryBuilder
5. Querybuilder finds specific entries in the cluster.
While using the prepareSearch()method for looking
for specific JSON documents in the cluster, we can use
query builders to customize the search results.. The
indexed data is shard across nodes in the cluster.
4. Based on the search criteria,
builds the query and returns the
data for the search criteria. This is
passed to Jackson and deserialized
to JSON and sent back to client.
6. Returns
necessary output
to the customer
Customer Booking Flow
API Gateway
Guest User
1. Choose the
respective Movie
and initiates
booking
N
8. Booking Details
Confirmation / Failure
shown to User
Booking
Microservice
2. JSON representation
of movies, screens and
theatres are given as
inputs from Search Flow
SeatSelected
Microservice
SeatSelected
Table
ReservationStatus
Microservice
Reservation
Status Table
Customer
Microservice
Customer
Table
Payment
Microservice
Payment Table
Booking
Table
7. Store
Booking
Details
Message
Queue
3.Flow continues till Seat
Selection flow, once Seat is
selected, the ReservationState in
Reservation Status table is
updated to “Initiated” and
SeatSelected is updated and a
TimerEvent is generated and
Payment Initiated.
Theatre External
System
Event
NotificationRece
iverService
5. ReceiverService is as well
triggered via a job and it
a. Reads the Event and
related Metadata from
the Queue
b. Formats message in
necessary format as per
the Theatre System and
delivers
c. This notifies the External
system to block the
seats
d. Receives Ack/Error from
Theatre System pushes
the event
SeatsBlockedEvent /
SeatsConfirmedEvent or
SeatsNotBlockedEvent
along with response
Metadata.
e. On
“BookingSuccessEvent”,
ticket booking is
confirmed.
Event
NotificationSenderS
ervice
4. SenderService is
triggered via a job and it
constructs the necessary
metadata from Booking
ReservationStatus ,
SeatSelected and Payment
table and builds a
respective event and
pushes it to Queue.
3a. Update
SeatSelected
NotificationEventService
6.NotificationEventService
triggers the Notifications to
users via SMS / eMails
Gateways . Updates the
ReservationStatus,
Notifications and Booking table
once Payment is successful.
Also creates a
“BookingSuccessEvent”.
Notifications
Table
3b. Update
ReservationStatus
3c. Update
Payment
Customer Notification Flow
SMS Store
EmailNotification
Microservice
On successful booking of tickets, events like
1. SendEmailMesssageEvent
2. SendSMSMessageEvent etc., along with
necessary MetaData are pushed to the
queue by a Sender job…
Email Store
SMSNotification
Microservice
Email
Gateway
SMS
Gateway
Appropriate receiver job pulls in the message from the queue,
constructs the necessary message from the Metadata and sends it
across to the recipient. Updates the necessary DB back with an
Ack/Error Events, along with necessary MetaData. As both SMS
and eMail are “Fire-and-Forget” no Ack/Err is pushed back to the
Booking Service and is not considered in this design…
1. EmalMesssagesSuccessfullySentEvent
2. SMSMessageSentEvent etc..
Technology Stack
User
Web UI /
Mobile App
Angular &
Native
API Gateway
Service
Registry
Zuul Proxy /
Spring Cloud
+ Boot
Eureka /
Spring Cloud
+ Boot
Service 1
Service N
Service 2
Spring Boot
SQL
NoSQL
NoSQL
Casandra
Payment Gateway API
(CCAvenue/Razorpay
/PayPal etc..)
Theatre External
System
SMS/eMail
Gateway API
Deployment Architecture
RDS Master RDS DB Instance Standby
Deployment Architecture
Containerization
Infrastructure + OS
Docker Engine
Docker Registry
$ docker push $ docker pull
Docker Image
App/Services
App/Services App/Services

Cinema booking system | Movie Booking System

  • 1.
    Agenda • Scope Definition •Architecture principles and guidelines • Domain Driven Design (DDD) Model • Solution Architecture • Detail Design • Technical Work Flow (Sequence flow) • Technology Stack – Recommendation • Deployment Architecture
  • 2.
    Scope To design aCinema Booking System • The site is used by consumers to book movie tickets. • Given a city, there are several theatres available. • Each theatre may have multiple screens. • Each screen may play multiple shows, with a different movie per show. • Each theatre may have a different seating arrangement. • When a user enters the site, he may search by a theatre or movie. • Based on the search results, user selects and books a ticket. • Each ticket may reserve up to 6 seats. • Booking must include a confirmed online payment. • On booking, user is notified via an SMS and email.
  • 3.
    Architecture principles andguidelines Design Principle Description Usecase Service replication Each service need to replicate, typically either Vertically or Horizontally. The most frequently used functionality is the Search functionality for the entire website. The service needs to replicate either Vertically or Horizontally as the quantum of search requests increases. Kubernetes provide a great way to replicate services easily using Replication Controller. Also with Autoscaling enabled in AWS would enable the container to scale vertically and horizontally. Service discovery Multiple services might be collaborating to provide an application’s functionality. Booking service needs data from Movie, Screen, Theatre etc.. Related services to initiate the ticket booking for the user. This requires the API gateway to identify and obtain the necessary handle . The API Gateway uses the Service Registry to perform service discovery. Netflix Eureka provides a good option for Service discovery. Netflix Eureka achieves high availability by running one or more Eureka servers in each Amazon EC2 availability zone. Resiliency High Availability and Disaster recovery For HA and DR its very important for services to automatically take corrective action and ensure the user experience is not impacted. For example, Netflix’s Hystrix provide an implementation of Circuit Breaker pattern to deal with software resiliency. Consistency To maintain consistency when performing transactions Use SQL where transactions should follow consistency and transaction level ACID properties need to be taken care off. Like ticket booking, updating the status from available to blocked to booked since it requires db transactions etc. AWS RDS provides a great facility for data replication and consistency in AWS.
  • 4.
    Architecture principles andguidelines Design Principle Description Usecase Availability To maintain high availability meeting 99.98% uptime SLAs. Use NoSQL while performing searches and mainly on data retrieval wherever High Availability needs to be achieved. Casandra is recommended. Elastic Search Seamless search for small and big data sets (Analytics) Excellent choice to perform fast search for large datasets with high availability requirements. As the search load increases, this ElasticSearch container can be autoscaled. Kafka Queue Queuing of Events for Notifications and Delivery Booking and Notifications flows has async operations which could be handled via queues. While booking tickets, there is a need to notify external systems. Queue is populated with appropriate messages/events along with metadata and the receiver service picks up the events and delivers to the External system. On Payment confirmation, there is a need to deliver SMS/Email to customers and as well notify back to the external theatre systems. Service monitoring Centralised logging easily identifies server problems or applications. Zipkin to gather timing data needed to troubleshoot latency problems in microservice, ELK (Elastic Search, LogStash, Kibana) for searching, analyzing, and visualizing log data in real-time. Allows you to identify any issues spanning multiple servers by correlating all the logs within a specified time frame. An open source tool which collects and stores logs, Logstash indexes the logs, while Kibana , a web interface, is used to view and search the logs already indexed.
  • 5.
  • 6.
    Solution Architecture API Gateway Service Service NoSQL Message Queue Web/ Mobile Client HTTP, Web SocketJSON, JWT Notifications HTTP Service Service SQL HTTP Service Publish Subscribe Client Side Server Side NoSQL External Systems Proprietary Formats Security and Access Mgmt Service Registry Rest API Rest API All services are exposed as REST. Sample shown here. No-SQL Use NoSQL while performing searches and mainly on data retrieval. Wherever High Availability needs to be achieved. SQL Use SQL where transactions should follow consistency and transaction level ACID properties need to be taken care off. Like ticket booking, updating the status from available to blocked to booked since it requires db transactions etc. JWT Access Token Rule Engine (Optional) Payment Gateway API (CCAvenue/Razorpay /PayPal etc..) Theatre External System SMS/eMail Gateway API Elastic Search Engine
  • 7.
    Detail Design API GatewayWeb Container API Web Gateway - MS Admin Container Location- MS Theatre - MS Movie - MS SeatStucture - MS ReservationStatus - MS Screens - MS Customer Container Customer - MS Payment Container PaymentGtwy - MS External System Container External Gateway - MS API & Auth Layer Micro Service Layer Admin & System Monitoring Layer Database Layer Eureka Eureka - MS Zipkin Zipkiin - MS ELK Elastic Search Logstash Kibana Rule Engine (Optional) Rule Engine - MS No-SQL DB Cluster Kafka Container Kafka Queue API Gateway Mobile Container API Mobile Gateway - MS Auth Container Authentication Server (OAuth2/OpenIDCon nect Server) Notification eMail - MS Booking Container SeatSeleced - MS Booking - MS SMS - MS Analytics Container (Optional) R Related - MS Search- MS SQL DB Cluster NOTE: All services are configured and managed via Kubernetes. Zipkin and ELK monitors their logs and state transition.
  • 8.
    Enabling Search withElastic Search API Gateway Location Microservice Location Store Movie Microservice Movie Store 5. Lookup Movies, Theatres based on Location 5a. Lookup Movies 4. Lookup Screen Details 4a. Return Screen details 6. JSON representation of movies, screens and theatres Theatre Microservice Theatre Store 2. Lookup Theatres for a location 2a. Return Location details 3. Lookup Theatre details 3a. Return Theatre details 7. Push the JSON representation of movies, screens and theatres to the ElasticSearch Cluster Screen Microservice Screen Store 2b. Return JSON representation of Location 3b. Return JSON Representation of Theatre 4b. Return JSON representation of Screen ES Spring Batch Framework – To trigger loading of JSON documents to Elastic Search Cluster (Spring Container) JavaScheduler Spring Application Context
  • 9.
    Customer Search Flow XContentBuil derService GuestUser Visits booking site Search request submitted 2. To convert JSON to Java Object API Gateway ES Elastic Search Container Jackson -> ObjectMapper 1. JSON representation of movies, screens and theatres is pushed to XContentBuilderService 3. prepareIndex() - this makes arbitary JSON document Searchable. prepareIndex SearchService QueryBuilder 5. Querybuilder finds specific entries in the cluster. While using the prepareSearch()method for looking for specific JSON documents in the cluster, we can use query builders to customize the search results.. The indexed data is shard across nodes in the cluster. 4. Based on the search criteria, builds the query and returns the data for the search criteria. This is passed to Jackson and deserialized to JSON and sent back to client. 6. Returns necessary output to the customer
  • 10.
    Customer Booking Flow APIGateway Guest User 1. Choose the respective Movie and initiates booking N 8. Booking Details Confirmation / Failure shown to User Booking Microservice 2. JSON representation of movies, screens and theatres are given as inputs from Search Flow SeatSelected Microservice SeatSelected Table ReservationStatus Microservice Reservation Status Table Customer Microservice Customer Table Payment Microservice Payment Table Booking Table 7. Store Booking Details Message Queue 3.Flow continues till Seat Selection flow, once Seat is selected, the ReservationState in Reservation Status table is updated to “Initiated” and SeatSelected is updated and a TimerEvent is generated and Payment Initiated. Theatre External System Event NotificationRece iverService 5. ReceiverService is as well triggered via a job and it a. Reads the Event and related Metadata from the Queue b. Formats message in necessary format as per the Theatre System and delivers c. This notifies the External system to block the seats d. Receives Ack/Error from Theatre System pushes the event SeatsBlockedEvent / SeatsConfirmedEvent or SeatsNotBlockedEvent along with response Metadata. e. On “BookingSuccessEvent”, ticket booking is confirmed. Event NotificationSenderS ervice 4. SenderService is triggered via a job and it constructs the necessary metadata from Booking ReservationStatus , SeatSelected and Payment table and builds a respective event and pushes it to Queue. 3a. Update SeatSelected NotificationEventService 6.NotificationEventService triggers the Notifications to users via SMS / eMails Gateways . Updates the ReservationStatus, Notifications and Booking table once Payment is successful. Also creates a “BookingSuccessEvent”. Notifications Table 3b. Update ReservationStatus 3c. Update Payment
  • 11.
    Customer Notification Flow SMSStore EmailNotification Microservice On successful booking of tickets, events like 1. SendEmailMesssageEvent 2. SendSMSMessageEvent etc., along with necessary MetaData are pushed to the queue by a Sender job… Email Store SMSNotification Microservice Email Gateway SMS Gateway Appropriate receiver job pulls in the message from the queue, constructs the necessary message from the Metadata and sends it across to the recipient. Updates the necessary DB back with an Ack/Error Events, along with necessary MetaData. As both SMS and eMail are “Fire-and-Forget” no Ack/Err is pushed back to the Booking Service and is not considered in this design… 1. EmalMesssagesSuccessfullySentEvent 2. SMSMessageSentEvent etc..
  • 12.
    Technology Stack User Web UI/ Mobile App Angular & Native API Gateway Service Registry Zuul Proxy / Spring Cloud + Boot Eureka / Spring Cloud + Boot Service 1 Service N Service 2 Spring Boot SQL NoSQL NoSQL Casandra Payment Gateway API (CCAvenue/Razorpay /PayPal etc..) Theatre External System SMS/eMail Gateway API
  • 13.
    Deployment Architecture RDS MasterRDS DB Instance Standby
  • 14.
    Deployment Architecture Containerization Infrastructure +OS Docker Engine Docker Registry $ docker push $ docker pull Docker Image App/Services App/Services App/Services