Command VS Event

Command với Command Handler là quan hệ 1:1
Event với Event Handler là quan hệ 1:*
Command theo hướng Push, theo thể chủ động, khi tôi muốn làm việc gì đó
Event là pull, theo hướng bị động, khi 1 sự việc đã thực hiện hoàn tất sẽ phát ra event để các subcrible thực hiện

Command những điều nên biết

1 Command chỉ nên là 1 DTO với các properties với các kiểu dữ liệu thuần tuý của ngôn ngữ như: string, int, float, array. Không nên là 1 object điều này giúp Command có khả năng di chuyển nhanh trong hệ thống, lưu xuống queue hay phục hồi lên dễ dàng.
1 Command nên bảo đảm tính không thể thay đổi được của nó, các thuộc tính chỉ nên được set value vào 1 lần tại hàm construct. Không nên thực hiện các hàm set value cho command. Điều này đảm bảo tính đúng đắn của 1 Command ngay từ đầu.
1 Command chỉ gắn với 1 Command Handler mà thôi, nó giúp dễ kiểm soát và thực thi.
Tất cả công việc trong command phải đảm bảo chỉ thực hiện trong 1 transaction mà thôi, để đảm bảo tính consistent của hệ thống.
1 Command phải luôn là đúng. Điều 1: Command phải đúng, Điều 2: nếu command sai thì nhìn lại điều 1 mà đi fix code. do vậy nên validate ngay khi tạo 1 command để đảm bảo nó đúng, và với tính không thể thay đổi, nó sẽ luôn đúng khi di chuyển trong hệ thống.
1 Command chỉ nên là Edit state không nên là Query (CQRS)

Command Bus VS Service Layer

Command bus thật chất chính là service layer nhưng được implement cung cấp thêm các tính năng để giải quyết các điểm yếu của service layer

Command Bus Service Layer
Chung 1 Interface Mỗi service có 1 interface riêng, gần như không có gì chung
Với việc tất cả đều được thực hiện chung 1 interface cho ta khả năng wrap 1 hành động nào trước khi thực hiện 1 Command, như start 1 transaction, validator… Lưu ý: điều này rất quan trọng, tất cả việc thực hiện trong 1 command chỉ nên trong 1 transaction. -khó có thể thêm được phần nào phía trước hay phía sau
1 Command chỉ thực hiện 1 việc, có 1 nhiệm vụ riêng, tăng tính SRP 1 Service thường thực hiện nhiều việc, dễ phụ thuộc vào nhiều domain điều này thường dẫn tới vi phạm tính SRP trong lập trình, cũng như nguyên tắc Open/Close
Hệ thống làm việc thông qua các command, tăng tính Hexagon của hệ thống (1 code có thể được dùng với nhiều endpoint) dễ tiếp cận theo hướng microservice

Từng bước để trở thành một lập trình viên giỏi


Bài viết được dịch từ blog Simple Programmer

Lời bàn của Vinacode:

Như trong bài viết “Tự học lập trình trong 10 năm” của Giáo sư Norvig thì chúng ta đã biết rằng để trở nên tinh thông bất cứ lĩnh vực gì thì ai cũng phải cần tối thiểu 10,000 giờ tập luyện (tương đương khoảng 10 năm). Nhưng bạn có thể nói rằng điều đó chẳng cần kết quả nghiên cứu của các nhà khoa học thì bạn cũng biết. Vấn đề ở đây là 10 năm là một quãng thời gian rất dài, và với 10 năm đó thì có thể đã “vật đổi sao dời” hay người còn kẻ mất. Điều quan trọng là làm sao duy trì được động lực làm việc và học tập trong một quãng thời gian dài như vậy?

Đúng vậy, để có thể duy trì được động lực trong một…

View original post 5,439 more words

10 Small Things You Can Do Every Day To Get Smarter

You might be under the impression that intelligence is a fixed quantity that is set when you are young and unchanging thereafter. But research shows that, if so, you’re wrong. How we approach situations and the things we do to feed our brains can significantly improve our mental horsepower.

That could mean going back to school or filling your bookshelves (or e-reader) with thick tomes on deep subjects, but getting smarter doesn’t necessarily mean a huge commitment of time and energy, according to a recent thread on question-and-answer site Quora.

When a questioner keen on self-improvement asked the community, “What would you do to be a little smarter every single day?” everyone from dedicated meditators to techies and entrepreneurs weighed in with useful suggestions. Which of these 10 ideas could you fit into your daily routine?

1. Be smarter about your online time. 

Every online break doesn’t have to be about checking social networks and fulfilling your daily ration of cute animal pics. The web is also full of great learning resources, such as online courses, intriguing TED talks, and vocabulary-building tools. Replace a few minutes of skateboarding dogs with something more mentally nourishing, suggest several responders.

2. Write down what you learn.

It doesn’t have to be pretty or long, but building a few minutes to reflect in writing about what you learned into each day is sure to boost your brainpower. “Write 400 words a day on things that you learned,” suggests yoga teacher Claudia Azula Altucher. Mike Xie, a research associate at Bayside Biosciences, agrees. “Write about what you’ve learned,” he advises.

3. Make a ‘did’ list.

A big part of intelligence is confidence and happiness, so boost both by pausing to list not the things you have yet to do, but all the things you’ve already accomplished. The idea of a “done list” is recommended by famed VC Marc Andreessen as well as Azula Altucher. “Make an I DID list to show all the things you, in fact, accomplished,” she suggests.

4. Get out the Scrabble board.

Board games and puzzles aren’t just fun; they can also be a great way to work out your brain. “Play games (Scrabble, bridge, chess, go, Battleship, Connect Four, doesn’t matter),” suggests Xie (for a ninja-level brain boost try to play without looking at the board to exercise your working memory). “Play Scrabble with no help from hints or books,” concurs Altucher.

5. Have smart friends.

It can be rough on your self-esteem, but hanging out with folks who are more clever than you is one of the fastest ways to learn. “Keep a smart company. Remember your IQ is the average of five closest people you hang out with,” Saurabh Shah, an account manager at Symphony Teleca, writes.

“Surround yourself with smarter people,” agrees developer Manas J. Saloi. “I try to spend as much time as I can with my tech leads. I have never had a problem accepting that I am an average coder at best and there are many things I am yet  to learn … Always be humble and be willing to learn.”

6. Read a lot.

OK, this is not a shocker, but it was the most common response, so though it might be a less-than-surprising answer, reading definitely seems essential. Opinions vary on what’s the best brain-boosting reading material, with suggestions ranging from developing a daily newspaper habit to picking up a variety of fiction and nonfiction, but everyone seems to agree that quantity is important. Read a lot.

7. Explain it to others. 

“If you can’t explain it simply, you don’t understand it well enough,” Albert Einstein said. The Quora posters agree. Make sure you’ve really learned what you think you have learned and that the information is well and truly stuck in your memory by trying to teach it to others. “Make sure you can explain it to someone else,” Xie says simply.

Student Jon Packles elaborates on this idea: “For everything you learn — big or small — stick with it for at least as long as it takes you to be able to explain it to a friend. It’s fairly easy to learn new information. Being able to retain that information and teach others is far more valuable.”

8. Do random new things. 

Shane Parrish, keeper of the consistently fascinating Farnam Street blog, tells the story of Steve Jobs’ youthful calligraphy class in his response on Quora. After dropping out of school, the future Apple founder had a lot of time on his hands and wandered into a calligraphy course. It seemed irrelevant at the time, but the design skills he learned were later baked into the first Macs. The takeaway: you never know what will be useful ahead of time. You just need to try new things and wait to see how they connect with the rest of your experiences later on.

“You can’t connect the dots looking forward; you can only  connect them looking backwards. So you have to trust that the dots will somehow connect in your future,” Parrish quotes Jobs as saying. To have dots to connect, you need to be willing to try new things — even if they don’t seem immediately useful or productive.

9. Learn a new language. 

No, you don’t need to become quickly fluent or jaunt off to a foreign country to master the language of your choosing. You can work away steadily from the comfort of your desk and still reap the mental rewards. “Learn a new language. There are a lot of free sites for that. Use Livemocha or Busuu,” Saloi says. (Personally, I’m a big fan of Memrise once you have the basic mechanics of a new language down.)

10. Take some down time.

It’s no surprise that dedicated meditator Altucher recommends giving yourself space for your brain to process what it’s learned — “sit in silence daily,” she writes — but she’s not the only responder who stresses the need to take some downtime from mental stimulation. Spend some time just thinking, suggests retired cop Rick Bruno. He pauses the interior chatter while exercising. “I think about things while I run (almost every day),” he reports.

Read more:

Vì sao người lương thiện cả đời gặp nỗi buồn và trắc trở?

Thanh Niên Tự Do


Tôi đã tìm một người thầy thông thái và đạo hạnh xin chỉ bảo:
-Vì sao những người lương thiện như con lại thường xuyên cảm thấy khổ, mà những người ác lại vẫn sống tốt như vậy

Thầy hiền hòa nhìn tôi trả lời:
– Nếu một người trong lòng cảm thấy khổ, điều đó nói lên rằng trong tâm người này có tồn tại một điều ác tương ứng. Nếu một người trong nội tâm không có điều ác nào, như vậy, người này sẽ không có cảm giác thống khổ. Vì thế, căn cứ theo đạo lý này, con thường cảm thấy khổ, nghĩa là nội tâm của con có tồn tại điều ác, con không phải là một người lương thiện thật sự. Mà những người con cho rằng là người ác, lại chưa hẳn là người thật sự ác.

Một người có thể vui vẻ…

View original post 1,360 more words


The initial phase of the responsive redesign of was a project that spanned 14 two weeks sprints. At the end of the sprint cycles we released a minimum viable product which we had to rapidly iterate to fill in some gaps that didn’t quite make the last mad dash. During this process we migrated fromScrum to Kanban as the pressure to get things fixed was as constant as the changing priority of requirements. Having been through this process I am not sure that I could go back to Sprints for the business as usual part of a project. However we have learnt a lot over the last few months and I thought I would share my lessons learnt in case you are also interested in making this transition.

Scrum to Kanban

  1. In order to release as often as possible, focus on smoke tests and automation of deployments between environments. Usually this requires a pretty complex setup that will take some time to find the optimal process.
  2. Use feature branches to allow small changes to be encapsulated and tested on each environment. This can take some getting used to but the pay off is well worth it.
  3. Don’t under estimate the power of a Dev Ops culture even if you don’t have a specific person for this role empowering both developers and testers to have the time to set everything up correctly will save you time and errors in the future.
  4. Break things down to the smallest possible developments based on the feedback that they can provide to avoid blockages. This doesn’t mean large projects can’t be done but should be packaged in multiple small releases.
  5. Limit work in progress (WIP) as well as items on the backlog. A large backlog is usually the most inefficient part of this process. No longer can it be the dumping ground for ground for random ideas. If it isn’t done within three months I auto delete and see what people complain about.
  6. Hold product performance meetings rather than sprint planning. Bring feedback and measurements and invite both business and development resources and let the data win the arguments. Setting the measurements up takes a while but they payoff of everyone looking at the right metrics is worth it. You will also need a solid goal to be aiming at.
  7. Much more conversation needed on a regular basis, we now hold product owner stand ups twice a week as talking every other week isn’t enough when you are moving that fast.
  8. Talk about problems define small solutions to provide learning then iterate.
  9. Whiteboards are your best friend. All of the walls in our new office are whiteboards and it really helps quick brainstorms. Also allows you to leave complex problems in visible place to revisit over time until solutions become clear.
  10. Don’t forget retrospectives.


Now that we have been running with Kanban for over three months it is amazing how much faster the team has become. Breaking things down into small pieces is probably the biggest skill that is needed to keep the process efficient. Also ensuring that the business are engaged throughout the process has taken some time but the benefit is huge. Agility has also increased as now when we find an issue or discover a new key piece of information you are able to act on it straight away rather than waiting until the next planning meeting. If you are interested in reading in more detail about Scrum vs Kanban then I highly recommend reading Scrum vs Kanban by Henrik Kniberg.