RSS feed [root] /design /weblog



title search:


Sun Sep 10 16:25:08 HKT 2017


(google search) (amazon search)
download zip of files only

Wed Sep 20 10:02:11 HKT 2017 From /weblog/design


Tired with duplicating Try-Catch for resource acquisition? Can try to create proxy method -[..]clarative-synchronization-with-java.html

Discussion of naming of if block -

Factors for choosing a strategic technology stack, runtime performance is not a factor for him, probably good idea -[..]1/04/factors-for-choosing-strategic.html

Don't think , stay focus -

Using class name as variable name is a bad thing? I doubt about it, but interesting idea -

The problem of using generic name -

Beware of where memory allocated, sometime there is no off side for lazy initalization -[..]ou-dare-to-change-hashmap-implementation

Some suggestion of how to code in order to prevent unreproducible bugs -[..]4/02/minimizing-unreproducible-bugs.html

More careful to check null -[..]et-paranoid-java-programming-techniques/

The fewer conditions you test for, the better your code “tastes”. -[..]ding-requirement-99749f37684a#.1glkhe7np

Think twice before running a loop -

Example of how to remove mutation status -

(google search) (amazon search)

Sun Sep 10 16:25:08 HKT 2017 From /weblog/design


Top Ten Software Architecture Mistakes -

Discussion about the balance of upfront design -[..]4/25/the-scatology-of-agile-architecture

There is no conflict in agile and architecture -[..]s-no-conflict-in-agile-and-architecture/

Experience of build instead of buy -[..]uy-one-companys-decision-to-go-it-alone/

Problem of too many layer -[..]/10/the-madness-of-layered-architecture/[..]are-architect-here-is-your-reading-list/

Sometime it is worth to build to throw -

Business Transactions
External Dependencies
Caching Strategy
Garbage Collection
Application Topology[..]s-to-capture-in-enterprise-applications/

invent a solution the majority of whose components depend on no others with those few components whose task it is to compose those other components being left largely to coordination roles. -[..]ting-started-with-big-data-architecture/

Twitter -[..]tter-handles-3000-images-per-second.html

Suning, more on HTTP -[..]oduct-details-system-architecture-design

Decision -

Some suggestion of making system simple, well, but the suggestion itself it is that simple -[..]ural-patterns-in-a-nutshell-a0b47a1e9013

(google search) (amazon search)

Thu Aug 31 10:36:38 HKT 2017 From /weblog/design

logging[..]08/12/16/7-good-rules-to-log-exceptions/ - look obvious but a lot of program still make those mistakes.

Do you prefer log more or log smarter? It is good to log smart but if you log more, even if you not smart enough, you still have the data. -

Basic log techniques -

Advances and Challenges in Log Analysis -

Filtering only useful stacktrace -[..]ter-irrelevant-stack-trace-lines-in.html

Some suggestion about logging -[..]/10-tips-proper-application-logging.html and

9 Logging Sins in Your Java Applications, the "Logging Plain User Input" is a good one -[..]9-logging-sins-in-your-java-applications

(google search) (amazon search)

Tue Aug 29 10:34:21 HKT 2017 From /weblog/design


Comment about the java document of jdk8 -[..]14/03/illuminating-javadoc-of-jdk-8.html

Thoughts On Comments -[..]ques/documentation/thoughts-on-comments/

The Art of Crafting Architectural Diagrams -

(google search) (amazon search)

Wed Aug 09 11:37:20 HKT 2017 From /weblog/design


Use present and absent rather than NULL -

Propose of enhancement, null handelers and null reference -[..]01/null-handelers-and-null-refere-1.html

How null breaks polymorphism -[..]s-polymorphism-or-the-problem-with-null/[..]orphism-or-the-problem-with-null-part-2/

Discussion about forbid NULL as parameter and return -[..]5/07/null-parameters-and-returning-null/

Default object in C# -[..]t/2012/09/25/Default-Objects-with-C.aspx

Discussion about using optional -

Some suggest about do something better than use null -

(google search) (amazon search)

Tue Aug 08 18:12:08 HKT 2017 From /weblog/design/distribute


Event Bus Implementation(s) -[..]2017/08/Summary-event-bus-implementation

(google search) (amazon search)

Thu Aug 03 18:22:14 HKT 2017 From /weblog/design


Refactoring to Patterns Catalog -

Article talk about the book:

Catagories smell into "smell in class" and "smell between class" -

Known but good to remind[..]10/01/6-steps-to-master-refactoring.html

An experience sharing -[..]m/2011/05/refactor-hudson-god-class.html[..]treme-Refactoring-with-Brian-Button.aspx

Refactoring should not introduce bug... -[..]01/so-why-are-you-refactoring-again.html

A way to have formal refactoring, through Feature Clustering, Rapid Scratch Refactoring and Twisting Classes -[..]rom-michael-feathers-brutal-refactoring/

Not all code change is refactoring - , and

Some common issues about refactoring code in a team -[..]/2008/01/28/dont-be-a-refactoring-bigot/[..]01/dangers-of-premature-refactoring.html , beware taking the balance -[..]ith-beautiful-code-the-refactor-syndrome

Refactory if needed -

Refactoring, when start, when stop? -

Refactoring metric -[..]rics-based-refactoring-for-cleaner-code/

Getting rid of util class
1) If the family of methods uses different parameters, depending on optional input or representations of the same input, then consider transforming the Helper via a fluent interface using the Builder pattern: from a collection of static methods like Helper.calculate(x), calculate(x, y), calculate(x, z), calculate(y, z) we could easily get to something like newBuilder().with(x).with(y).calculate(). The helper class would then offer behaviours, reduce its list of business methods and provide more flexibility for future extensions. Callers would then use it as internal field for reuse or instantiate it where needed. The helper class (as we knew it) disappeared.
2) If the helper class provides methods which are actually actions for different inputs (but, at this point, for the same domain), consider applying the Command pattern: the caller will actually create the required command (which will handle the necessary input and offer a behaviour) and an invoker will execute it within a certain context. You may get a command implementation for each static method and your code would move from an Helper.calculate(x, y), calculate(z) to something like invoker.calculate(new Action(x, y)). Bye bye helper class.
3) If the helper class provides methods for the same input but different logics, consider applying the Strategy pattern: each static method may easily become a strategy implementation, vanishing the need of its original helper class (replaced by a context component then).
4) If the given set of static methods concerns a certain class hierarchy or a defined collection of components, then consider applying the Visitor pattern: you may get several visitor implementations providing different visit methods which would probably replace partially or entirely the previously existing static methods.
5) If none of the above cases met your criteria, then apply the three most important indicators: your experience, your competences in the given project and common sense.[..]-to-get-rid-of-helper-and-utils-classes/

Converting forloop to streaming -

Refactoring JavaScript from Sync to Async in Safe Baby-Steps -

code-refactoring-dos-donts -

(google search) (amazon search)

Wed Jul 19 14:59:51 HKT 2017 From /weblog/design


Avoid circular dependencies between packages!

2 common approach, by function or by layer -

(google search) (amazon search)

Tue Jul 18 11:31:43 HKT 2017 From /weblog/design


A nice thread of discussing how to comment in code -

A Taxonomy Of Comments -[..]hniques/documentation/taxonomy-comments/

Everything have 2 sides -[..]s/documentation/comments-costs-benefits/

Example of comment haven't update freq enough -[..]even-good-code-comments-deteriorate.html[..]health-to-comment-or-not-to-comment.html

(google search) (amazon search)

Sun Mar 19 10:25:58 HKT 2017 From /weblog/design


The Hidden Dividends of Microservices -

Best practices -[..]constructing-micro-service-system-part03

Compare using library / service -[..]cy-management-whether-library-or-service

(google search) (amazon search)

Thu Mar 09 23:13:09 HKT 2017 From /weblog/design


Someone saying that having private method is anti-pattern, here is the discussion -

Discussion of encapsulation -[..]/encapsulation-does-it-really-exist.html

My view on this is that most of the time there's little value in self-encapsulation. The value of encapsulation is proportional to the scope of the data access. Classes are usually small (at least mine are) so direct access isn't going to be an issue within that scope. Most accessors are simple assignments for the setter and retrieval for the getter, so there's little value in using them internally. -

(google search) (amazon search)

Thu Feb 23 16:14:03 HKT 2017 From /weblog/design/interview


Interview with JOOQ founder -

(google search) (amazon search)

Tue Feb 21 17:44:20 HKT 2017 From /weblog/design


A paper show the evolution of a DSL -

A stock trading order example of DSL -[..]05/designing-internal-dsls-in-scala.html

What is the difference between API / DSL if we don't write a parser for our language? From Martin Fowler's blog - , it is mentioned:
Piers Cawley makes the point that a key characteristic of DSLs is their narrow focus on a domain.
I think this is a very good summary, usually if most of the APIs are getXXX() , setXXX(), loadXXX() , createXXX() ........ Then we mostly design APIs that expose low level detail to the API user to work on, which, is work but user probably work nicer if we can come up with language like API that allow users to do their work in more descriptive level.

I think if API design like that usually it will reduce the code duplication, what ever real duplication or conceptual duplication. It probably already apply "Tell, don't ask" style -

A discussion about applying "Tell, don't ask" which lead to message passing architecture -[..]07/10/do_messages_want_to_be_asynchr.php

And other discussion about "Tell, don't ask"[..]/2008/11/demeters-law-tell-dont-ask.html[..]part-two-demeters-law-tell-dont-ask.html[..]rt-three-demeters-law-tell-dont-ask.html

One good sample with explaination -[..]-it-really-domain-specific-language.html

Few links -

From CRUD to DDD -[..]2/15/from-crud-to-domain-driven-fluency/

I like this: "XML abuse reduction (conducting an “XML Intervention”)" -[..]ps-internal-dsl-draft-outline-notes.aspx

DSL maybe the result of encapsulation -

Excellent implementation of extending java yourself -

How DSL method named -[..]he-java-fluent-api-designer-crash-course

(google search) (amazon search)

Thu Feb 16 00:03:22 HKT 2017 From /weblog/design/pattern


(google search) (amazon search)

Tue Feb 07 15:44:58 HKT 2017 From /weblog/design


Nothing specific, mostly code clean up, refactoring and simplification, the performance boost was a surprise. <- This is a good one -[..]12/07/disruptor-v3-faster-hopefully.html

Is there anything we can do about this when designing algorithms and data-structures? Yes there is a lot we can do. If we perform chunks of work on data that is co-located, and we stride around memory in a predictable fashion, then our algorithms can be many times faster. For example rather than using bucket and chain hash tables, like in the JDK, we can employ hash tables using open-addressing with linear-probing. Rather than using linked-lists or trees with single items in each node, we can store an array of many items in each node. -[..]emory-access-patterns-are-important.html

Skip lists are used instead of b-trees because b-trees don’t scale. -[..]ast-mvcc-inmem-lockfree-codegen-and.html

Beware about the performance issue of static initalization -[..]-cause-problems-with-multi-threading-how

Experiment show why arraylist is better in most cases -

How to design low latency application in java -[..]5/chronicle-and-low-latency-in-java.html[..]ciples-of-high-performance-programs.html[..]principles-of-high-performance-programs/

Suggestion about how to determine number of thread pool -[..]rmine-Web-Applications-Thread-Poll-Size/

Beware the performance penalty of logging -

Keep thing dynamic -[..]ciples-of-high-performance-programs.html[..]st-rule-of-performance-optimisation.html[..]u/~rcs/research/interactive_latency.html[..]aling-data-platforms.html?SSLoginOk=true

Discuss about developing low latency financial application -

Discussion of object pooling -[..]-but-forgotten-trick-object-pooling.html[..]m_performance_part_1_object_pooling.html

Efficiency - the amount of work you need to do.
Performance - how fast you can do that work
Efficiency - governed by your algorithm
Performance - governed by your data structures.[..]e-difference-between-efficiency-and.html

Turning off power save mode on the CPU reduced brought the max latency from 11 msec down to 8 msec.
Guaranteeing threads will always have CPU resources using CPU isolation and thread affinity brought the maximum latency down to 14 microseconds.[..]eduler-jitter-using-cpu-isolation-a.html[..]

About design for performance for webapi -[..]y-decision-as-a-service-design-patterns/

check list -[..]ery-software-development-team-should-ask

Beware if system utilization over 80% -[..]/20/service-latency-and-utilisation.html

scalable-io-events-vs-multithreading-based -[..]lable-io-events-vs-multithreading-based/

How to find out bottleneck -[..]entile-latencies-in-Chronicle-Queue.html

(google search) (amazon search)

Mon Jan 23 18:33:07 HKT 2017 From /weblog/design/concurrency


Stealing thread -

Intel Guide for Developing Multithreaded Applications -[..]or-developing-multithreaded-applications

Difference ways to stop a thread -[..]ept_url=/hpc-high-performance-computing/

Interesting, I am not sure if I agree, but chrome ( which use fork ) are really cool in performance:
There’s another problem with Unix programming in Ruby that I’ll just touch on briefly: Java people and Windows people. They’re going to tell you that fork(2) is bad because they don’t have it on their platform, or it sucks on their platform, or whatever, but it’s cool, you know, because they have native threads, and threads are like, way better anyways.

Fuck that.

Don’t ever let anyone tell you that fork(2) is bad. Thirty years from now, there will still be a fork(2) and a pipe(2) and a exec(2) and smart people will still be using them to solve hard problems reliably and predictably, just like they were thirty years ago.

MRI Ruby people need to accept, like Python (you have seen multiprocessing, yes?), that Unix processes are one of two techniques for achieving reliable concurrency and parallelism in server applications. Threads are out. You can use processes, or async/events, or both processes and async/events, but definitely not threads. Threads are out.

1x1 win M*N -

Best number of threads:
N = number of CPUs
U = target CPU utilization (0 <= U <= 1)
W/C = ration of wait time to cpu time (measured through profiling)

threads = N * U * (1 + W/C) -[..]ratio-of-java-threads-to-cpus-on-solaris

Another post about tuning thread pool -[..]ortance-of-tuning-your-thread-pools.html

Threads Basics -

The Dos and Don'ts of Multithreading -[..]-26-09-low-level-threading-table-of.html

(google search) (amazon search)

Tue Jan 17 23:09:08 HKT 2017 From /weblog/design


(google search) (amazon search)

Tue Jan 17 22:58:18 HKT 2017 From /weblog/design


5 Hints You're Using A Map When You Should Be Using a Cache? -[..]ints-your-using-map-when-you-should.html

How hibernate design the cache -

Consider to do more careful update, not just update DB and dirty cache, but update DB and cache in a same time -

Caching can be architectural smell, some hint and some alternative -[..]2/is_caching_an_architectural_smell.html

General caching discussion -[..]are-architecture/caching-techniques.html[..]10-program-busting-caching-mistakes.html[..]B/web-cache/cachingmistakes.aspx?azid=74

(google search) (amazon search)

Wed Dec 07 18:48:22 HKT 2016 From /weblog/design

work with legacy

Simple ways to improve legacy code -

One approach to work with legacy code, instead of phrase by phrase or part by part, identify and improve the domain part first -[..]-efforts-to-replace-legacy-systems-fail/[..]egacy-applications-tests-modularization/

Note of common point for refactoring with legacy application -[..]/2016/10/unintentionally-obfuscated.html

(google search) (amazon search)

Tue Nov 29 00:12:57 HKT 2016 From /weblog/design/interview


"They build their own infrastructure for performance, reliability, and cost control reasons. By building it themselves they never have to say Amazon went down because it was company X's fault. Their software may not be more reliable than others, but they can fix, debug, and deployment much quicker than when working with a 3rd party."

Shel Kaphan -

(google search) (amazon search)

Tue Nov 15 10:53:50 HKT 2016 From /weblog/design

value object

Discussion of DTO -

Discussion of value object -

(google search) (amazon search)

Tue Nov 15 10:49:25 HKT 2016 From /weblog/design/concurrency


How to write safer concurrency code -

reentrant and thread safe functions -[..]/31/reentrant-and-thread-safe-functions/

Libraries / toolkits for multicore process -[..]intableArticle.jhtml?articleID=212900103

Introduction -[..]QQSNDLRSKHSCJUNN2JVN?articleID=212903586[..]CQSNDLRSKHSCJUNN2JVN?articleID=213001517

Collections of links -[..]rallel-Or-Get-Left-Behind.html&Itemid=29

Briefing of difference modeling of threading system -[..]intableArticle.jhtml?articleID=215900465[..]inners-guide-to-multithreaded-libraries/[..]haloms_blog/2010/08/concurrency-101.html

Saving the Failwhale: The Art of Concurrency (Page last updated December 2012, Added 2012-12-26, Author Dhanji R. Prasanna, Publisher informit). Tips:

1) Contention is unavoidable - some resources are just slower, and you must wait for them. The secrets to good concurrency are 1) ensuring that these slower resources are rarely used, and 2) during such waiting periods, giving the faster tiers other work to do so that they continue to be utilized well.
2) Overuse of synchronization constructs such as locks and mutexes leads to systems that perform poorly under load.
3) ConcurrentHashMap is an efficient thread-safe map while HashMap is not thread-safe.
4) ConcurrentHashMap doesn't do away with locks, it still uses them but it uses more than the single global lock, so that threads gain some measure of concurrency. It uses separate locks for partitions, so that multiple threads writing to the map are likely to access different partitions, using separate locks and therefore process their data simultaneously. This technique is known as lock-striping. Efficient striping uses a number of locks proportional to the number of CPU cores in a system.
5) The asynchronous processing model smooths resource spikes by adding requests to a queue which is serviced by a pool of workers - spikes in requests make the queue grow rather than overloading the workers. (The ExecutorService is essentially a thread pool accompanied by a task queue.)

Discussion of using difference model for concurrency -[..]cks-application-architecture-pros-a.html

Concurrency vs Parallelism -[..]/2013/12/concurrency-vs-parallelism.html

Compare between Actors, CSP, Disruptor and raw Threads -[..]omparision-of-different-concurrency.html

Few coding tips that should be useful for most languages -[..]erformance-scalability-and-liveness.html[..]2015/09/java-concurrency-essentials.html

Service Design
Do one thing, do it well
No shared operational state
Bound your queues
Name custom thread pools and register an UncaughtExceptionHandler
Prefer immutable data objects over mutable state[..]-to-25-billion-notifications-during.html

(google search) (amazon search)

Wed Nov 02 16:14:20 HKT 2016 From /weblog/design/pattern


understanding-retry-pattern-with-exponential-back-off-and-circuit-breaker-pattern -[..]al-back-off-and-circuit-breaker-pattern/

(google search) (amazon search)

Wed Nov 02 16:13:31 HKT 2016 From /weblog/design/concurrency


10-ways-to-reduce-lock-contention-in-threaded-programs -[..]ce-lock-contention-in-threaded-programs/

Discussion about lock the form and prevent 2 user edit it in the same time and currupt the object, what is the possible drawback. -[..]-optimistic-locking-isnt-a-silver-bullet

futexes -[..]ds/browse_thread/thread/3c3608a779dc6731

Spinning -[..]ome/lock-free-algorithms/tricks/spinning

Locks for rarely changed data, sound like good suggestion -[..]pic/comp.programming.threads/dyrbRKsj4gw

Try to use non-blocking approach if possible -[..]1/locks-condition-variables-latency.html

Concurrency without lock, and even without correctness? -

Single write principle -[..].au/2011/09/single-writer-principle.html

Comparing difference kind of locks again -[..]11/stampedlocktryoptimisticread-and.html

10-ways-to-reduce-lock-contention-in-threaded-programs -[..]ce-lock-contention-in-threaded-programs/

(google search) (amazon search)