Another book review, this time about how to build a social network with ASP.NET 4.0.
Note: Free evaluation copy provided by the publisher.
Title: ASP.NET 4 Social Networking
Author: Atul Gupta, Sudhanshu Hate, Andrew Siemer
This book is about how to build a Social Network (a fish owners one as an example), by using ASP.NET, C# and some frameworks: MEF, EF, ADO.NET EF.
Some of those frameworks are not lightweight but at the same time they are very ordered and the code is well structured so swapping is easy.
Some interesting points or highlights after reading it:
Uses an events-based newsfeed, same principle as facebook does. Nice details as being able to hide stuff.
Friendly urls for profiles and other sections, in fact, sometimes is a bit overabused to search for SEO, when a social network might be more private. But just having the concept of forums… means the authors wanted to add as much "social stuff" as possible, even if doesn't't fully fit.
Precalculates and stores different photo sizes on upload (right), but does it synchronously (wrong, can get to long waits or timeouts).
Lazy loading vs eager loading, the endless discussion (here decides to do eager loading of some things).
User search is pretty basic, using LINQ to search in a few fields.
Blogs are curiously created: Allow to publish public posts (even with friendly urls), but doesn't syndicates in a RSS feed so limits that public exposure.
Builds a forum, quite extrange and atypical in a social network (is among the RSS one of the things they have semi-killed). Voting, marking forum replies as answers and user rankings are... a bit out of scope for a social network, more fit for a pure forum. At least the ratings are correctly decoupled and system-wide usable (providing good extensibility).
Very simple privacy management in general: Either public or private, with
just some cases of membership/access requests.
Last chapter presents scalability advices: Moving to a SOA architecture (with
WCF), separating frontend servers to a farm with load balancing, service servers
and DB tier, caching using AppFabric's Caching component or Memcached. Also
moves the email sending process to a queued, async. system. Also mentions
logical deletion and then system process to wipe deleted items, DB Indexing and
data partitioning (does SQL Server level partitioning instead of handling it via
code), and Lucene.NET for searching.
But also has some cons:
- Uses database table relationships (referential inegrity via DB), uncommon due to caching problems
- HTML inside messages in service layers
- Favors code-behind dynamic html generation instead of using subviews
- Stores profile avatar images in the DB (ouch!)
- Friendship defined as one-way relation (instead in the more flexible two-way friend-friend relation).This results in crap code related to it (like friend search), because it must have "originator ID is friend of X” OR "destination ID is friend of X”.
- Presentation entities to lessen the problem of eager loading (but not avoiding it, just lowering memory usage).
- And the .NET 4 in the name... would have worked equally with 3.5 (I can't recall anything FW4.0 specific in the book).
- Dynamic attributes idea is nice but not scalable (even less needing to rows in different tables for each attribute.
As for the results, as you could expect, an architecture clean and not badly designed, but that won't scale if the site gets successful and grows. Still, it represents a good start, just don't expect anything exceptional or highly optimized for medium websites.
As a conclusion, the book won't show you groundbreaking secrets nor incredible algorithms, but will set the basis for a decent social network with low usage and quite some features. You will probably want to cut out some unwanted features, but the code is easy to read and well structured. Way better coded than other book I reviewed.