<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">


<META content="MSHTML 6.00.6000.16414" name=GENERATOR></HEAD>
<BODY>
<DIV>
<DIV><SPAN class=120271121-12112007><FONT face=Arial color=#0000ff size=2>I 
suggest worrying about your DB schema first.</FONT></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><FONT face=Arial color=#0000ff size=2>Do you 
want person^2 entries<SPAN class=323121321-12112007> in your 
DB</SPAN>?</FONT></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><FONT face=Arial color=#0000ff size=2>Once 
you settle on your DB schema, then just mirror it in 
memcached.</FONT></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2>Are connections reflexive?&nbsp; If A is a 
friend of B, does that imply B is a</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2>friend of A?</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2></FONT></SPAN></SPAN>&nbsp;</DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2>I think any DBA would like option 2 
better.</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2></FONT></SPAN></SPAN>&nbsp;</DIV>
<DIV><SPAN class=120271121-12112007><FONT face=Arial color=#0000ff size=2>Brian 
Beuning</FONT></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><FONT face=Arial color=#0000ff 
size=2></FONT></SPAN>&nbsp;</DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2>SHARED</FONT></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2>&nbsp;</DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2>create table 
People&nbsp;(</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; personID 
int,</FONT></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; name 
varchar(50),</FONT></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN 
class=323121321-12112007>&nbsp;&nbsp;&nbsp; -- more personal info 
columns</SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp; primary key 
(personID)</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff 
size=2>)</FONT></SPAN></SPAN></DIV></FONT></SPAN></SPAN>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2></FONT></SPAN></SPAN>&nbsp;</DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2>OPTION 1
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2></FONT></SPAN></SPAN><SPAN 
class=120271121-12112007><SPAN class=323121321-12112007><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN></SPAN>&nbsp;</DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2>create table Relations 
(</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; Aid 
int,</FONT></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp;&nbsp;data 
blob,&nbsp;&nbsp;&nbsp; -- contains HashMap table</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN 
class=323121321-12112007></SPAN></SPAN><SPAN class=120271121-12112007><SPAN 
class=323121321-12112007><FONT face=Arial><FONT color=#0000ff 
size=2>&nbsp;&nbsp;&nbsp; primary key (Aid)</FONT></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2>)</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN 
class=323121321-12112007></SPAN></SPAN>&nbsp;</DIV></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2>OPTION 2</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2></FONT></SPAN></SPAN><SPAN 
class=120271121-12112007><SPAN class=323121321-12112007><FONT face=Arial 
color=#0000ff size=2></FONT></SPAN></SPAN>&nbsp;</DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2>create table Relations 
(</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; Aid 
int,</FONT></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2>&nbsp;&nbsp;&nbsp; Bid 
int,</FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; type 
int,</FONT></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp; primary key (Aid, 
Bid)</FONT></FONT></SPAN></SPAN></DIV>
<DIV><SPAN class=120271121-12112007><SPAN class=323121321-12112007><FONT 
face=Arial color=#0000ff size=2>)</FONT></SPAN></SPAN></DIV></SPAN></DIV>
<BLOCKQUOTE>
  <DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma 
  size=2>-----Original Message-----<BR><B>From:</B> Rakesh Rajan 
  [mailto:rakeshxp@gmail.com]<BR><B>Sent:</B> Saturday, November 10, 2007 7:14 
  AM<BR><B>To:</B> memcached@lists.danga.com<BR><B>Subject:</B> Storage Plan: 
  Map v/s linear<BR><BR></FONT></DIV>Hi Folks,<BR><BR>I am trying to use 
  memcached to store the relationships between persons ( So person A -&gt; 
  Relationship Type -&gt; Person B )&nbsp; ( Java based solution )<BR><BR>So 
  given a person, I would need <BR>1) To see if another person is a connection 
  <BR>2) And the connection type.<BR><BR>As I see it, I could implement this in 
  2 ways<BR><BR><B>OPTION 1</B><BR><BR>For each user store a HashMap of&nbsp; 
  personID,relationshipType. 
  <BR>e.g<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  Map&lt;Integer,Integer&gt; relationMap = new HashMap&lt;Integer,Integer&gt;(); 
  <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; 
  relationMap.put(1,1); 
  .......<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  memcache.put( "prefix" + sourcePersonID ,&nbsp; relationMap);<BR><BR>In this 
  case, there would be as many keys in memcached, as there are 
  persons.<BR><BR><BR><B>OPTION 2</B><BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp; Use both 
  person IDs in the memcahe key.<BR>&nbsp;&nbsp; 
  e.g<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; memcache.put( "prefix" + 
  sourcePersonID + ":"+ targetPersonID ,&nbsp; relationType);<BR><BR>In this 
  case, there would be at max persons^2&nbsp; keys in memcahed. 
  <BR><BR><BR><B>Assumptions</B><BR>1) Each person would have an average of 
  200-300 friends<BR>2) Memcahed would be on a different set of servers compared 
  to the webapps ( So there would be a N/W delay in passing the data from 
  memcached -&gt; webapp ) <BR><BR>I would like to know which of option is 
  better for my requirement ? 
<BR><BR>Thanks,<BR>Rakesh<BR></BLOCKQUOTE></BODY></HTML>