Deployment
System Design Python Script
py
import math
def calculate_dau_mau_ratio(dau, mau):
return mau / dau
def calculate_memory_usage(dau, profile_size_kb, mau, objects_per_user, metadata_size_kb):
user_profile_memory = dau * profile_size_kb # KB
metadata_memory = mau * objects_per_user * metadata_size_kb # KB
return user_profile_memory / 1024, metadata_memory / 1024 # Convert to MB
def calculate_content_storage(mau, uploads_per_user, avg_video_size_mb):
return mau * uploads_per_user * avg_video_size_mb # MB
def calculate_total_storage(user_profile_mb, metadata_mb, content_mb, replication_factor, backup_overhead):
primary_storage = user_profile_mb + metadata_mb + content_mb # MB
total_storage = primary_storage * replication_factor * (1 + backup_overhead)
return total_storage / 1024 # Convert to GB
def calculate_bandwidth(dau, requests_per_session, avg_request_size_kb, session_duration_min, bitrate_mbps):
daily_request_bandwidth_kb = dau * requests_per_session * avg_request_size_kb # KB/day
streaming_bandwidth_kb = dau * session_duration_min * (bitrate_mbps * 1024 / 8) # KB
total_bandwidth_gb = (daily_request_bandwidth_kb + streaming_bandwidth_kb) / (1024 * 1024) # Convert to GB
return total_bandwidth_gb
def calculate_qps(dau, requests_per_session, hours_active_per_day, peak_factor):
total_requests_per_day = dau * requests_per_session
avg_qps = total_requests_per_day / (hours_active_per_day * 3600)
peak_qps = avg_qps * peak_factor
return avg_qps, peak_qps
# Main Program
def main():
print("\n--- System Design Calculator ---\n")
# Input Assumptions
dau = int(input("Enter Daily Active Users (DAU): "))
mau = int(input("Enter Monthly Active Users (MAU): "))
profile_size_kb = float(input("Enter average user profile size (in KB): "))
objects_per_user = int(input("Enter average objects (tasks/videos) per user/month: "))
metadata_size_kb = float(input("Enter metadata size per object (in KB): "))
uploads_per_user = int(input("Enter uploads per user per month (for content apps): "))
avg_video_size_mb = float(input("Enter average content size (e.g., video in MB): "))
requests_per_session = int(input("Enter average number of requests per session: "))
avg_request_size_kb = float(input("Enter average request size (in KB): "))
session_duration_min = float(input("Enter average session duration per user (in minutes): "))
bitrate_mbps = float(input("Enter average bitrate (for streaming apps in Mbps): "))
replication_factor = int(input("Enter replication factor: "))
backup_overhead = float(input("Enter backup overhead percentage (e.g., 0.2 for 20%): "))
hours_active_per_day = int(input("Enter hours users are active per day: "))
peak_factor = float(input("Enter peak factor multiplier (e.g., 2 for 2x traffic during peak): "))
# Calculations
mau_dau_ratio = calculate_dau_mau_ratio(dau, mau)
user_profile_mb, metadata_mb = calculate_memory_usage(dau, profile_size_kb, mau, objects_per_user, metadata_size_kb)
content_mb = calculate_content_storage(mau, uploads_per_user, avg_video_size_mb)
total_storage_gb = calculate_total_storage(user_profile_mb, metadata_mb, content_mb, replication_factor, backup_overhead)
total_bandwidth_gb = calculate_bandwidth(dau, requests_per_session, avg_request_size_kb, session_duration_min, bitrate_mbps)
avg_qps, peak_qps = calculate_qps(dau, requests_per_session, hours_active_per_day, peak_factor)
# Output Results
print("\n--- Results ---\n")
print(f"1. MAU/DAU Ratio: {mau_dau_ratio:.2f}")
print(f"2. User Profile Memory: {user_profile_mb:.2f} MB")
print(f"3. Metadata Memory: {metadata_mb:.2f} MB")
print(f"4. Content Storage: {content_mb / 1024:.2f} GB")
print(f"5. Total Storage (with replication & backups): {total_storage_gb:.2f} GB")
print(f"6. Total Bandwidth Required: {total_bandwidth_gb:.2f} GB/day")
print(f"7. Average QPS: {avg_qps:.2f}")
print(f"8. Peak QPS: {peak_qps:.2f}")
print("\n--- End of Report ---\n")
if __name__ == "__main__":
main()