100 likes | 168 Views
Database design considerations for a financial system. Louie Bao. Data Types. Date over Datetime Most financial data such as prices, portfolio holdings, etc are date based and not concerned with the time component.
E N D
Database design considerations for a financial system Louie Bao
Data Types • Date over Datetime • Most financial data such as prices, portfolio holdings, etc are date based and not concerned with the time component. • The separate Date data type introduced since SQL 2008 significantly reduces date comparison and calculation mistakes.
Data Types • Decimal over Float • Decimal is a precise numerical type whereas Float is an approximate numerical type. • Decimal over Money • Money data type suffers from integer division.
Data Access • Read Committed or RCSI over NOLOCK NOLOCK is bad because: • Uncommitted rows might be returned. • Same record might be accounted twice. • Previously committed rows might be missed. • Query might fail with an error: Could not continue scan with NOLOCK due to data movement.
Data Reconciliation • HashBytes over Checksum • When an MD5 hash algorithm is specified, the probability of HashBytes returning the same result for two different inputs is much lower than that of CHECKSUM.
Data Traceability • Pass as many IDs as far downstream as possible • FileId • AccountId • OrderId • TradeId • SecurityId • etc
Logging • Process Event Log • Info • Warning • Error • Process Progress Log • Started • Running • Completed • Process Exception Log • Invalid/unknown data
Auditing • History Tables • Keep track of who changed what when how. Audit Columns
Security • Group permission over User permission • Add and remove users with ease. • Align permissions with business functions • Testers should not have write access in prod.
References Throw Your MONEY Away http://bradsruminations.blogspot.com.au/2009/11/throw-your-money-away.html Previously committed rows might be missed if NOLOCK hint is used http://blogs.msdn.com/b/sqlcat/archive/2007/02/01/previously-committed-rows-might-be-missed-if-nolock-hint-is-used.aspx Timebomb - The Consistency problem with NOLOCK / READ UNCOMMITTED http://sqlblogcasts.com/blogs/tonyrogerson/archive/2006/11/10/1280.aspx