"This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/system-design-primer-primer)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Design an online chat"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Constraints and assumptions\n",
"\n",
"* Assume we'll focus on the following workflows:\n",
" * Text conversations only\n",
" * Users\n",
" * Add a user\n",
" * Remove a user\n",
" * Update a user\n",
" * Add to a user's friends list\n",
" * Add friend request\n",
" * Approve friend request\n",
" * Reject friend request\n",
" * Remove from a user's friends list\n",
" * Create a group chat\n",
" * Invite friends to a group chat\n",
" * Post a message to a group chat\n",
" * Private 1-1 chat\n",
" * Invite a friend to a private chat\n",
" * Post a meesage to a private chat\n",
"* No need to worry about scaling initially"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Solution"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Overwriting online_chat.py\n"
]
}
],
"source": [
"%%writefile online_chat.py\n",
"from abc import ABCMeta\n",
"\n",
"\n",
"class UserService(object):\n",
"\n",
" __metaclass__ = Singleton\n",
"\n",
" def __init__(self):\n",
" self.users_by_id = {} # key: user id, value: User\n",
This notebook was prepared by [Donne Martin](https://github.com/donnemartin). Source and license info is on [GitHub](https://github.com/donnemartin/system-design-primer-primer).