Cracking the coding interview Q7-12 | chaozh.com
7.7 Explain how you would design a chat server In particular, provide details about the various backend components, classes, and methods. What would be the hardest problems to solve?
We can learn from twitter and QQ server design. The main concepts of the chat server would be user(status), chat group and messages.
enum Status{offline, online, away} struct Message{ User from_user; User to_user; String post_message;} class User {Status type; Message posts[]; sendMessage(); addGroup(); updateStatus(); createGroup(); } struct Group { Message posts[]; User list[];}
Information sync with memory cache and database; Server scale; User session management;
7.9 Explain the data structures and algorithms that you would use to design an in-memory file system. Illustrate with an example in code where possible
File system must inlude dir and file structure. The key points are design of super block, directory and inodes. Super block mainly deal with namespace and organize inodes, which we could use hash table for fast fetching. Inodes contains meta data and organize datas, which we could use B tree (memory efficient) or radix tree(linux, fast fetching) or log structure (journaling tech for availability). Directory mainly deal with file lookup operations which convert string path to the rightful inode.
Read full article from Cracking the coding interview Q7-12 | chaozh.com
No comments:
Post a Comment