Simple Counter
Requirement
Use case
- end user click button to send vote
- boardcast vote distribution for graph ploting to device, for last 10 mins
Env
- devices on street
- kiosks with touch screen
- no abuse
- security protected
UI
- current vote of each candidate
- ploting graphs
Operation
- performance. repsonse by 1s
- availability, high available
- scalability, horizonatally scalable; auto scale up/down base on load?
Initiative
- enable realtime vote distribution boardcasting
Assumptions
- in hong kong only
- expected response time to end user is 1s
Design
Model
Candidate
- id: String
- displayName: String
Vote
- candidate: Candidate.id
- created: timestamp
- deivce: deviceId
To query sum of vote group by candidate:
db.Vote.aggregate(
[
{
$group : {
_id : { candidate: $candidate },
count: { $sum: 1 }
}
}
]
)
System Archtecture
Auto scaling
The application can be horizontally scaled since it's stateless.
- Using EC2 Auto Scaling, Application Load Balancers, Cloud Watch. The application can be horiztonally auto-scaled up and down.
- Ensure session stickiness is enabled Application Load Balancers, websocket is supported by default in standard HTTP, HTTPS ports
- Health checks assure connections aren't routed to unhealthy instances, Setup scaling policies so that we can do auto scale up and down base on CPU utilization. Metrics that's used for CPU utilization monitoring comes from CloudWatch.