Skip to content

Commit

Permalink
Update from original (#1)
Browse files Browse the repository at this point in the history
* Add license disclaimer (donnemartin#76)

Clearly denote the repository license is from me, not my employer (Facebook).

* Fix asynchronism link in Mint README (donnemartin#69)

* Fix lowercase typo in Layer 7 load balancing title (donnemartin#74)

* Fix donnemartin#79: Inaccuracy in Twitter timeline and search example (donnemartin#81)

* Fix typo (donnemartin#75)

* Init spot_size member in parking lot exercise (donnemartin#83)

* Add prev to Node class (donnemartin#82)

For managing an LRU cache, we need to use a doubly linked list for move_to_front() operation.

* Fix reducer argument in pastebin exercise (donnemartin#85)

* Add polish translation link (donnemartin#89)

* Fix typo in denormalization section (donnemartin#95)

* Add policy for adding new blogs to Company engineering blogs section (donnemartin#96)

* Add Russian translation link (donnemartin#91)

* Treat solution subdirectories as containing Python packages (donnemartin#99)

* Add Japanese translation link (donnemartin#101)

* Add traditional Chinese translation link (donnemartin#105)

* Add Italian translation link (donnemartin#106)

* Fix typo: considering to consider in scaling AWS solution (donnemartin#109)

* Add API rate limiter design link (donnemartin#108)

* Add Korean translation link (donnemartin#111)

* Simplify logic for is_ace and is_face_card in deck of cards solution (donnemartin#113)

* Add Persian translation link (donnemartin#115)

* Correct Redis list structure in Twitter solution (donnemartin#116)

* Add Japanese Translation (donnemartin#114)

* Update Japanese translation link (donnemartin#118)

* ja: Fix typo (donnemartin#119)

* Make some minor wording/formatting changes (donnemartin#120)

* add Twitter Handles 3,000 Images Per Second

* Add Netflix in Company Architectures (donnemartin#122)

* Add Vietnamese translation link (donnemartin#128)

* Add Scaling Uber in Company Architecture (donnemartin#123)

* Update master-slave section anchor (donnemartin#129)

* Add Facebook Live Streams (donnemartin#125)

* Update contributing guidelines - PR squash (donnemartin#135)

* Update re:Invent url (donnemartin#137)

* Add Traditional Chinese translation (donnemartin#133)

* zh-TW: Add proper line break to links (donnemartin#139)

* Add Greek translation link (donnemartin#140)

* Convert all .py files to be valid Python (donnemartin#98)

* zh-Hans: Fix typos (donnemartin#141)

* Add Spanish translation link (donnemartin#142)

* Add missing colons to class methods (donnemartin#143)

* Add missing self variables to Deck of Cards solution (donnemartin#145)

* Add deque import to Social Graph solution (donnemartin#147)

* Change LARGE to VehicleSize.LARGE in parking lot solution (donnemartin#146)

* zh-TW: Fix comment format (donnemartin#155)

* Fix coding errors (donnemartin#149)

* Fix dict KeyError (donnemartin#152)

* Fix dict KeyError (donnemartin#153)

* Adding missing self variable (donnemartin#158)

* Add missing enum imports (donnemartin#157)

* Change variable seller to category in Mint solution (donnemartin#159)

* zh-Hans: Fix typo (donnemartin#161)

* Replace broken SQL tuning links (donnemartin#163)

* zh-Hans: Fix PostgreSQL typo (donnemartin#166)

* Fix donnemartin#148: Add State(Enum) to social_graph_snippets.py (donnemartin#167)

* ja: Swap VARCHAR and CHAR translation error (donnemartin#169)

* Add Arabic translation link (donnemartin#177)

* Add newlines - PEP8 style (donnemartin#173)

* zh-TW: Improve translations (donnemartin#176)

* Fix typo in LRU cache solution (donnemartin#182)

* Fix broken links (donnemartin#180)

* Add German translation link (donnemartin#188)

* Add Thai translation link (donnemartin#190)

* Fix broken URL (donnemartin#194)

* Fix error in Twitter timeline solution (donnemartin#196)

* Fix wording in call center solution (donnemartin#197)

* Resolve donnemartin#195: Fix broken GitHub URLs (donnemartin#199)

* zh-Hans: Fix typo: 'Twitter' (donnemartin#200)

* Update Twitter/Facebook exercise description (donnemartin#202)

* Fix typo in CAP theorem section (donnemartin#205)

* Fix broken links (donnemartin#204)

* Fix donnemartin#126: Update link to Anki decks (donnemartin#206)

* Fix typo in Design Pastebin.com exercise (donnemartin#210)

* zh-Hans: Fix translation (donnemartin#208)

* zh-Hans: Update translation (donnemartin#212)

* zh-Hans: Update translation (donnemartin#209)

* Update Cassandra architecture links (donnemartin#213)

* Update README intro (donnemartin#216)

* Resolve donnemartin#214: Add reference links to message queues section (donnemartin#218)

* Update Scalability for Dummies link (donnemartin#224)

* ja: Fix typo (donnemartin#226)

* zh-TW: Update index anchors (donnemartin#227)

* Add Link: A 360 Degree View Of The Entire Netflix Stack (donnemartin#229)

* Fix donnemartin#228: Address mutex latency discrepancy (donnemartin#233)

* Add Bengali translation link (donnemartin#242)

* Add missing word in cache write through discussion (donnemartin#245)

* zh-Hans: Fix typo (donnemartin#246)

* Fix grammar in document store section (donnemartin#247)

* Fix typo in Twitter timeline and search solution (donnemartin#251)

* Update document-store to document store (donnemartin#255)

* Enable Python syntax highlighting in Pastebin sample code (donnemartin#257)

* Fix broken SQL link in Scaling AWS exercise (donnemartin#258)

Fix broken SQL link in Scaling AWS exercise

* Update HDFS design link to the latest version (donnemartin#275)

* Enable syntax highlighting in all python code snippets (donnemartin#268)

* Translate language list (donnemartin#252)

* Add Ebook generation script (donnemartin#207)

* Add availability in numbers section (donnemartin#237)

* Update language lists in translations (donnemartin#280)

* Add Hebrew translation link (donnemartin#286)

* zh-Hans: Translate Pastebin solution (donnemartin#273)

* ja: Fix typo of Big-O notation in KVS section (donnemartin#292)

* JA: Fix mistranslation in Horizontal scaling section

- The Japanese translation is ambiguous about “vertical scaling” means scaling out or scaling up.
- The word “expensive” is missing in the Japanese translation.

* JA: Fix mistranslation in Reverse proxy (web server) section

- Fix mistranslation of parallel structure. (not information/blacklist/limit, but hide/blacklist/limit)

* ja: Fix mistranslation in "Horizontal scaling"

* JA: Fix mistranslation in Weak consistency section (donnemartin#299)

* JA: Fix mistranslation in Push CDNs section (donnemartin#300)

* JA: Fix mistranslation in Federation section (donnemartin#303)

* ja: Fix translation in "Anki flashcards" (donnemartin#306)

* ja: Fix translation in “Disadvantage(s): load balancer” (donnemartin#307)

* ja: Fix translation in Service Discovery section (donnemartin#308)
  • Loading branch information
godelian authored Oct 9, 2019
1 parent 5072dfe commit ef29857
Show file tree
Hide file tree
Showing 38 changed files with 4,318 additions and 256 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Byte-compiled / optimized / DLL files
*.epub
__pycache__/
*.py[cod]

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Translations to new languages are always welcome, especially if you can maintain
* Invite friends to review if possible. If desired, feel free to invite friends to help your original translation by letting them fork your repo, then merging their PRs.
* Add links to your translation at the top of every README*.md file. (For consistency, the link should be added in alphabetical order by ISO code, and the anchor text should be in the native language.)
* When done, indicate on the PR that it's ready to be merged into the main repo.
* Once accepted, your PR will be squashed into a single commit into the `master` branch.

### Translation template credits

Expand Down
6 changes: 6 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
I am providing code and resources in this repository to you under an open source
license. Because this is my personal repository, the license you receive to my
code and resources is from me and not my employer (Facebook).

Copyright 2017 Donne Martin

Creative Commons Attribution 4.0 International License (CC BY 4.0)

http://creativecommons.org/licenses/by/4.0/
1,787 changes: 1,787 additions & 0 deletions README-ja.md

Large diffs are not rendered by default.

122 changes: 62 additions & 60 deletions README-zh-Hans.md

Large diffs are not rendered by default.

1,786 changes: 1,786 additions & 0 deletions README-zh-TW.md

Large diffs are not rendered by default.

226 changes: 139 additions & 87 deletions README.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions epub-metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
title: System Design Primer
creator: Donne Martin
date: 2018
40 changes: 40 additions & 0 deletions generate-epub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#! /usr/bin/env sh

generate_from_stdin() {
outfile=$1
language=$2

echo "Generating '$language' ..."

pandoc --metadata-file=epub-metadata.yaml --metadata=lang:$2 --from=markdown -o $1 <&0

echo "Done! You can find the '$language' book at ./$outfile"
}

generate_with_solutions () {
tmpfile=$(mktemp /tmp/sytem-design-primer-epub-generator.XXX)

cat ./README.md >> $tmpfile

for dir in ./solutions/system_design/*; do
case $dir in *template*) continue;; esac
case $dir in *__init__.py*) continue;; esac
: [[ -d "$dir" ]] && ( cd "$dir" && cat ./README.md >> $tmpfile && echo "" >> $tmpfile )
done

cat $tmpfile | generate_from_stdin 'README.epub' 'en'

rm "$tmpfile"
}

generate () {
name=$1
language=$2

cat $name.md | generate_from_stdin $name.epub $language
}

generate_with_solutions
generate README-ja ja
generate README-zh-Hans zh-Hans
generate README-zh-TW zh-TW
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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)."
"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)."
]
},
{
Expand All @@ -24,9 +24,9 @@
" * Operator, supervisor, director\n",
"* Can we assume operators always get the initial calls?\n",
" * Yes\n",
"* If there is no free operators or the operator can't handle the call, does the call go to the supervisors?\n",
"* If there is no available operators or the operator can't handle the call, does the call go to the supervisors?\n",
" * Yes\n",
"* If there is no free supervisors or the supervisor can't handle the call, does the call go to the directors?\n",
"* If there is no available supervisors or the supervisor can't handle the call, does the call go to the directors?\n",
" * Yes\n",
"* Can we assume the directors can handle all calls?\n",
" * Yes\n",
Expand Down
11 changes: 8 additions & 3 deletions solutions/object_oriented_design/call_center/call_center.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ def _dispatch_call(self, call, employees):
return employee
return None

def notify_call_escalated(self, call): # ...
def notify_call_completed(self, call): # ...
def dispatch_queued_call_to_newly_freed_employee(self, call, employee): # ...
def notify_call_escalated(self, call):
pass

def notify_call_completed(self, call):
pass

def dispatch_queued_call_to_newly_freed_employee(self, call, employee):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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)."
"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)."
]
},
{
Expand Down Expand Up @@ -89,11 +89,11 @@
" super(BlackJackCard, self).__init__(value, suit)\n",
"\n",
" def is_ace(self):\n",
" return True if self._value == 1 else False\n",
" return self._value == 1\n",
"\n",
" def is_face_card(self):\n",
" \"\"\"Jack = 11, Queen = 12, King = 13\"\"\"\n",
" return True if 10 < self._value <= 13 else False\n",
" return 10 < self._value <= 13\n",
"\n",
" @property\n",
" def value(self):\n",
Expand Down
11 changes: 6 additions & 5 deletions solutions/object_oriented_design/deck_of_cards/deck_of_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def add_card(self, card):

def score(self):
total_value = 0
for card in card:
for card in self.cards:
total_value += card.value
return total_value

Expand All @@ -92,7 +92,7 @@ def score(self):

def possible_scores(self):
"""Return a list of possible scores, taking Aces into account."""
# ...
pass


class Deck(object):
Expand All @@ -102,9 +102,9 @@ def __init__(self, cards):
self.deal_index = 0

def remaining_cards(self):
return len(self.cards) - deal_index
return len(self.cards) - self.deal_index

def deal_card():
def deal_card(self):
try:
card = self.cards[self.deal_index]
card.is_available = False
Expand All @@ -113,4 +113,5 @@ def deal_card():
return None
return card

def shuffle(self): # ...
def shuffle(self):
pass
2 changes: 1 addition & 1 deletion solutions/object_oriented_design/hash_table/hash_map.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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)."
"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)."
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion solutions/object_oriented_design/hash_table/hash_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ def remove(self, key):
if item.key == key:
del self.table[hash_index][index]
return
raise KeyError('Key not found')
raise KeyError('Key not found')
11 changes: 6 additions & 5 deletions solutions/object_oriented_design/lru_cache/lru_cache.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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)."
"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)."
]
},
{
Expand All @@ -21,7 +21,7 @@
"## Constraints and assumptions\n",
"\n",
"* What are we caching?\n",
" * We are cahing the results of web queries\n",
" * We are caching the results of web queries\n",
"* Can we assume inputs are valid or do we have to validate them?\n",
" * Assume they're valid\n",
"* Can we assume this fits memory?\n",
Expand Down Expand Up @@ -56,7 +56,8 @@
"\n",
" def __init__(self, results):\n",
" self.results = results\n",
" self.next = next\n",
" self.prev = None\n",
" self.next = None\n",
"\n",
"\n",
"class LinkedList(object):\n",
Expand All @@ -83,7 +84,7 @@
" \n",
" Accessing a node updates its position to the front of the LRU list.\n",
" \"\"\"\n",
" node = self.lookup[query]\n",
" node = self.lookup.get(query)\n",
" if node is None:\n",
" return None\n",
" self.linked_list.move_to_front(node)\n",
Expand All @@ -96,7 +97,7 @@
" If the entry is new and the cache is at capacity, removes the oldest entry\n",
" before the new entry is added.\n",
" \"\"\"\n",
" node = self.lookup[query]\n",
" node = self.lookup.get(query)\n",
" if node is not None:\n",
" # Key exists in cache, update the value\n",
" node.results = results\n",
Expand Down
23 changes: 14 additions & 9 deletions solutions/object_oriented_design/lru_cache/lru_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ def __init__(self):
self.head = None
self.tail = None

def move_to_front(self, node): # ...
def append_to_front(self, node): # ...
def remove_from_tail(self): # ...
def move_to_front(self, node):
pass

def append_to_front(self, node):
pass

def remove_from_tail(self):
pass


class Cache(object):
Expand All @@ -24,25 +29,25 @@ def __init__(self, MAX_SIZE):
self.lookup = {} # key: query, value: node
self.linked_list = LinkedList()

def get(self, query)
def get(self, query):
"""Get the stored query result from the cache.
Accessing a node updates its position to the front of the LRU list.
"""
node = self.lookup[query]
node = self.lookup.get(query)
if node is None:
return None
self.linked_list.move_to_front(node)
return node.results

def set(self, results, query):
"""Set the result for the given query key in the cache.
When updating an entry, updates its position to the front of the LRU list.
If the entry is new and the cache is at capacity, removes the oldest entry
before the new entry is added.
"""
node = self.lookup[query]
node = self.lookup.get(query)
if node is not None:
# Key exists in cache, update the value
node.results = results
Expand All @@ -58,4 +63,4 @@ def set(self, results, query):
# Add the new key and value
new_node = Node(results)
self.linked_list.append_to_front(new_node)
self.lookup[query] = new_node
self.lookup[query] = new_node
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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)."
"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)."
]
},
{
Expand Down
52 changes: 38 additions & 14 deletions solutions/object_oriented_design/online_chat/online_chat.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
from abc import ABCMeta
from enum import Enum


class UserService(object):

def __init__(self):
self.users_by_id = {} # key: user id, value: User

def add_user(self, user_id, name, pass_hash): # ...
def remove_user(self, user_id): # ...
def add_friend_request(self, from_user_id, to_user_id): # ...
def approve_friend_request(self, from_user_id, to_user_id): # ...
def reject_friend_request(self, from_user_id, to_user_id): # ...
def add_user(self, user_id, name, pass_hash):
pass

def remove_user(self, user_id):
pass

def add_friend_request(self, from_user_id, to_user_id):
pass

def approve_friend_request(self, from_user_id, to_user_id):
pass

def reject_friend_request(self, from_user_id, to_user_id):
pass


class User(object):
Expand All @@ -25,12 +35,23 @@ def __init__(self, user_id, name, pass_hash):
self.received_friend_requests_by_friend_id = {} # key: friend id, value: AddRequest
self.sent_friend_requests_by_friend_id = {} # key: friend id, value: AddRequest

def message_user(self, friend_id, message): # ...
def message_group(self, group_id, message): # ...
def send_friend_request(self, friend_id): # ...
def receive_friend_request(self, friend_id): # ...
def approve_friend_request(self, friend_id): # ...
def reject_friend_request(self, friend_id): # ...
def message_user(self, friend_id, message):
pass

def message_group(self, group_id, message):
pass

def send_friend_request(self, friend_id):
pass

def receive_friend_request(self, friend_id):
pass

def approve_friend_request(self, friend_id):
pass

def reject_friend_request(self, friend_id):
pass


class Chat(metaclass=ABCMeta):
Expand All @@ -51,8 +72,11 @@ def __init__(self, first_user, second_user):

class GroupChat(Chat):

def add_user(self, user): # ...
def remove_user(self, user): # ...
def add_user(self, user):
pass

def remove_user(self, user):
pass


class Message(object):
Expand All @@ -77,4 +101,4 @@ class RequestStatus(Enum):
UNREAD = 0
READ = 1
ACCEPTED = 2
REJECTED = 3
REJECTED = 3
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"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)."
"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)."
]
},
{
Expand Down Expand Up @@ -71,7 +71,7 @@
" def __init__(self, vehicle_size, license_plate, spot_size):\n",
" self.vehicle_size = vehicle_size\n",
" self.license_plate = license_plate\n",
" self.spot_size\n",
" self.spot_size = spot_size\n",
" self.spots_taken = []\n",
"\n",
" def clear_spots(self):\n",
Expand Down
Loading

0 comments on commit ef29857

Please sign in to comment.