Evolutionary Database Design.docx
《Evolutionary Database Design.docx》由会员分享,可在线阅读,更多相关《Evolutionary Database Design.docx(9页珍藏版)》请在冰豆网上搜索。
EvolutionaryDatabaseDesign
EvolutionaryDatabaseDesign
Overthelastfewyearswe'vedevelopedanumberoftechniquesthatallowadatabasedesigntoevolveasanapplicationdevelops.Thisisaveryimportantcapabilityforagilemethodologies.Thetechniquesrelyonapplyingcontinuousintegrationandautomatedrefactoringtodatabasedevelopment,togetherwithaclosecollaborationbetweenDBAsandapplicationdevelopers.Thetechniquesworkinbothpre-productionandreleasedsystems.
January2003
MartinFowler
PramodSadalage
Translations:
JapaneseRussian
Contents
∙DealingwithChange
oLimitations
∙ThePractices
oDBAscollaboratecloselywithdevelopers
oEverybodygetstheirowndatabaseinstance
oDevelopersfrequentlyintegrateintoasharedmaster
oAdatabaseconsistsofschemaandtestdata
oAllchangesaredatabaserefactorings
oAutomatetherefactorings
oAutomaticallyUpdateallDatabaseDevelopers
oClearlyseparatealldatabaseaccesscode
∙Variations
oKeepingmultipledatabaselineages
oYoudon'tneedaDBA
∙ToolstoHelp
∙FurtherStepsandFurtherInformation
Inthelastfewyears,we'veseentheriseofanewbreedofsoftwaremethodologies,theagilemethodologies.Thesemakesomenewandsignificantdemandsondatabasedesign.Oneofthemostcentralofthesedemandsistheideaofevolutionarydesign.Onanagileprojectyouassumethatyoucannotfixtherequirementsofthesystemup-front.Asaresulthavingadetaileddesignphaseatthebeginningofaprojectbecomesimpractical.Thedesignofthesystemhastoevolvethroughthevariousiterationsofthesoftware.Agilemethods,inparticularextremeprogramming(XP),haveanumberofpracticesthatmakethisevolutionarydesignpractical.
Manypeoplehavequestionedwhetherevolutionarydesigncanbeappliedtoasystemwithalargedatabasecomponent.Indeedmanypeopletoldusthatitwasimpossible-atroublingthoughtasThoughtWorksembarkedonalargedatabase-orientedprojectusingmanyagileandXPtechniques.
Thisarticledescribesthepracticesthatwe'veusedtoallowustodothisimpossiblething.Wewon'tsaythatwe'vecompletelysolvedthedatabaseevolutionproblem,butwedothinkwe'vedemonstratedasetoftechniquesthatmanypeoplewillfinduseful.
DealingwithChange
Oneoftheprimaryfeaturesofagilemethodsistheirattitudetowardschange.Mostofthethinkingaboutsoftwareprocessisaboutunderstandingrequirementsearly,signingoffontheserequirements,usingtherequirementsasabasisfordesign,signingoffonthat,andthenproceedingwithconstruction.Thisisaplan-drivencycle,oftenreferredto(usuallywithderision)asthewaterfallapproach
Suchapproacheslooktominimizechangesbydoingextensiveup-frontwork.Oncetheearlyworkisdone,changescausesignificantproblems.Asaresultsuchapproachesrunintotroubleifrequirementsarechanging,andrequirementschurnisabigproblemforsuchprocesses.
Agileprocessesapproachchangedifferently.Theyseektoembracechange,allowingchangestooccurevenlateinadevelopmentproject.Changesarecontrolled,buttheattitudeoftheprocessistoenablechangeasmuchaspossible.Partlythisisinresponsetotheinherentinstabilityofrequirementsinmanyprojects,partlyitistobettersupportdynamicbusinessenvironmentsbyhelpingthemchangewiththecompetitivepressures.
Inordertomakethiswork,youneedadifferentattitudetodesign.Insteadofthinkingofdesignasaphase,whichismostlycompletedbeforeyoubeginconstruction,youlookatdesignasanon-goingprocessthatisinterleavedwithconstruction,testing,andevendelivery.Thisisthecontrastbetweenplannedandevolutionarydesign.Oneofthevitalcontributionsofagilemethodsisthattheyhavecomeupwithpracticesthatallowevolutionarydesigntoworkinacontrolledmanner.Soinsteadofthecommonchaosthatoftenhappenswhendesignisn'tplannedup-front,thesemethodsprovidetechniquestocontrolevolutionarydesignandmakethempractical.
Animportantpartofthisapproachisiterativedevelopment,whereyouruntheentiresoftwarelife-cyclemanytimesduringthelifeofaproject.Agileprocessesruncompletelifecyclesineachiteration,completingtheiterationwithworking,tested,integratedcodeforasmallsubsetoftherequirementsofthefinalproduct.Theseiterationsareshort,usuallyrunningbetweenaweekandacoupleofmonths,withapreferencetowardsshorteriterations.
Whilethesetechniqueshavegrowninuseandinterest,oneofthebiggestquestionsishowtomakeevolutionarydesignworkfordatabases.Mostpeopleconsiderthatdatabasedesignissomethingthatabsolutelyneedsup-frontplanning.Changingthedatabaseschemalateinthedevelopmenttendstocausewide-spreadbreakagesinapplicationsoftware.Furthermorechangingaschemaafterdeploymentresultinpainfuldatamigrationproblems.
Overthecourseofthelastthreeyearswe'vebeeninvolvedinalargeproject(calledAtlas)thathasusedevolutionarydatabasedesignandmadeitwork.Theprojectinvolvedalmost100peopleinmultiplesitesworld-wide(US,Australia,andIndia).Itisaroundhalfamillionlinesofcodeandhasover200tables.Thedatabaseevolvedduringayearandahalfofinitialdevelopmentandcontinuestoevolveeventhoughit'sinproductionformultiplecustomers.Duringthisprojectwestartedwithiterationsofamonth,butafterafewmonthschangedtotwoweekiterationswhichworkedbetter.Thetechniqueswedescribeherearetheonesthatwe(ormoreaccuratelyPramod)usedtomakethiswork.
Sincethatprojectgotgoingwe'vespreadthesetechniquesovermoreofourprojects,gainingmoreexperiencefrommorecases.We'vealsofoundinspiration,ideas,andexperiencefromotheragileprojects.
Limitations
Beforewediveintothetechniques,it'simportanttostatethatwehaven'tsolvedalltheproblemsofevolutionarydatabasedesign.Inparticular:
∙Wedevelopedanapplicationdatabaseforasingleapplicationratherthananintegrationdatabasethattriestointegratemultipledatabases.
∙Wedon'thavetokeeptheproductiondatabasesup24/7
Wedon'tconsidertheseproblemstobeinherentlyunsolvable,afterallmanypeoplebelievedwecouldn'tsolvethisone.Butuntilwedo,wewon'tclaimwecansolvethemeither.
ThePractices
Ourapproachtoevolutionarydatabasedesigndependsonahandfulofimportantpractices.
DBAscollaboratecloselywithdevelopers
Oneofthetenetsofagilemethodsisthatpeoplewithdifferentskillsandbackgroundsneedtocollaborateverycloselytogether.Theycan'tcommunicatemainlythroughformalmeetingsanddocuments.Insteadtheyneedtobeouttalkingwitheachotherandworkingwitheachotherallthetime.Everybodyisaffectedbythis:
analysts,PMs,domainexperts,developers...andDBAs.
EverytaskthatadeveloperworksonpotentiallyneedsaDBA'shelp.BoththedevelopersandtheDBAneedtoconsiderwhetheradevelopmenttaskisgoingtomakeasignificantchangetothedatabaseschema.IfsothedeveloperneedstoconsultwiththeDBAtodecidehowtomakethechange.Thedeveloperknowswhatnewfunctionalityisneeded,andtheDBAhasaglobalviewofthedataintheapplication.
TomakethishappentheDBAhastomakehimselfapproachableandavailable.Makeiteasyforadevelopertojustpopoverforafewminutesandasksomequestions.MakesuretheDBAsanddeveloperssitclosetoeachothersotheycaneasilygettogether.EnsurethatapplicationdesignsessionsareknownaboutsotheDBAcanpopineasily.InmanyenvironmentsweseepeopleerectingbarriersbetweentheDBAandapplicationdevelopmentfunctions.Thesebarriersmustcomedownforanevolutionarydatabasedesignprocesstowork.
Everybodygetstheirowndatabaseinstance
Evolutionarydesignrecognizesthatpeoplelearnbytryingthingsout.Inprogrammingtermsdevelopersexperimentwithhowtoimplementacertainfeatureandmaymakeafewattemptsbeforesettlingdowntoapreferredalternative.Databasedesigncanbelikethattoo.Asaresultit'simportantforeachdevelopertohavetheirownsandboxwheretheycanexperiment,andnothavetheirchangesaffectanyoneelse.
ManyDBAexpertsseemultipledatabasesasanathema,toodifficulttoworkinpractice,butwe'vefoundthatyoucaneasilymanageahundredorsodatabaseinstances.Thevitalthingistohavetotoolstoallowyoutomanipulatedatabasesmuchasyouwouldmanipulatefiles.
Developersfrequentlyintegrateintoasharedmaster
Althoughdeveloperscanexperimentfrequentlyintheirownarea,it'simportanttobringthedifferentapproachesbacktogetheragainfrequently.Anapplicationneedsasharedmasterdatabasethatallworkflowsfrom.Whenadeveloperbeginsatasktheycopythemasterintotheirownworkspace,manipulate,andthenintegratetheirchangesbackintothemaster.Asaruleofthumbeachdevelopershouldintegrateonceaday.
Let'stakeanexamplewhereMikestartsadevelopmenttaskat10am(assumingheactuallycomesinthatearly).Aspartofthistaskheneedstochangethedatabaseschema.Ifthechangeiseasy,likeaddingacolumn,hejustdecideshowtomakethechangehimself,Mikealsomakessurethecolumnhewantstoadddoesnotalreadyexistinthedatabase,withthehelpofthedatadictionary(discussedlater).Ifit'smorecomplicatedthenhegrabstheDBAandtalksoverthelikelychangeswithhim.
Oncehe'sreadytobeginhetakesacopyofthedatabasemasterandcanmodifyboththedatabaseschemaandcodefreely.Ashe'sinasandboxanychangeshemakesdon'timpactanyoneelse's.Atsomepoint,sayaround3pm,he'sprettycomfortablethatheknowswhatthedatabasechangeneedstobe,ev