Design patterns and strategies for implementing data layer(3-tier architecture)

Recently I’ve been reading a lot about design patterns and abstractions regarding the data layer from the 3 tier architecture architectural pattern. It seems that I always mess things up there. However I’m finding it difficult to get the pros and cons of every pattern and when to apply it.

  1. When should I use ORM and when should I avoid one
  2. When shouLld I implement reporistory pattern and when not, also is repository pattern strictly used only by DDD, or it’s fine to create repositories even if I don’t have entities implemented as classes(only logically)
  3. Table gateway and row gateways – When should I apply them and when I should avoid them, why would I use them instand of ORM

Are there any other patterns beside the ones listed above. Also I would like to ask for study-case. May some open-source application which has very good data layer or example from book.

Usage patterns for spring cloud gateway on aws

Consider this setup for a microservices application on AWS. enter image description here

The question is about the API gateway part. AWS has one for managing the API of microservices. It has an authentication mechanism built-in, but this application needs an API Gateway which needs to interact with the database, for the request authorization and few custom headers verification, which to my knowledge is not possible.

One alternative is the spring cloud gateway, which again will be a spring boot app. All the other services are deployed in an ECS cluster. The gateway cannot in the same cluster, as the load balancing needs to be taken care of by gateway app. That means below is the one possible set up I am knowing of. enter image description here

Now questions part:

  • Is this really the way spring cloud gateway is used in microservices context? Or is this wrong solution for this purpose?
  • Is this one wrong solution, what are the suggested alternatives. For this, the condition is the app needs to run on both AWS and non-AWS environments

PS: If this question is not appropriate for this site, suggest possible alternatives.

Block all calls except for certain white-list patterns

Thanks in advance for any thoughts you might have. It seems that this should be a very simple question/concept, but damn me if I can find the answer I am looking for. I apologize if I missed something obvious.

My phone is a Note 8 on Verizon. I am looking for a call blocking app that will kill most incoming calls, but allow certain area codes to ring. That is, I would love to be able to use a wild card in the whitelist.

For example, I want to block any calls, except for those from area codes 314 and 302. Those calls should ring. But how can I white list the area code?

“Call Blocker” from VLMob.com seems to get close. It has the ability to block all calls, except those on a whitelist. But the whitelist does not seem to be like wild cards. Any thoughts? Alternative suggestions?

Thanks!

Reactive streams guidelines, patterns and anti-patterns

This is a question about reactive / observable streams, MVI and similar. It’s a set of sub-questions, but I feel they are very coupled, so posting it as one question to capture the similarities.

I’ve been trying to learn concepts around this and I’ve run into several problems while doing that. Here are my observations:

  • Resources (articles, books, videos) are either too low-level (just discussing the API) or too high-level (how to connect two microservices). No discussion about the problems and solutions with using observables within a medium-size app

  • Examples are almost always toy examples with 1-3 streams. No discussion about the problems you face when you have 20 or 100 streams and solutions to those

  • Examples are also almost always static. Streams are pre-wired on startup. No discussion about the problems and solutions related to cases where streams come and go, managing subscriptions and such

  • There are many disagreements and contradictions. Some people suggest using subjects a lot, others suggest never using them. Some people suggest using streams everywhere, some only on the fringes of the system. Some are in favor of a lot of small events and streams, while others prefer coarse-grained structure

Questions arising from the above:

  • Are there medium-sized open-source apps built using reactive streams that I can look at to try to answer these questions myself?

  • Are there any resources that I missed provide answers to some of the questions above?

  • Do you have personal experience with either reactive streams or any other reactive system from which patterns / anti-patterns translate to reactive streams?

  • In general, is there a list of guidelines, patterns and anti-patterns when using reactive streams in medium-sized apps?

What are some good patterns for cleaning up noisy logging alerts

In addition to traditional logging from applications going into e.g. Elasticsearch, an organisation may have an alerting system “Sentry” that receives log messages/exception events sent by applications over HTTP, and notifies developers of potential problems.

Suppose that Sentry now contains not only “actionable” events (e.g. error connecting to the database. Devops should investigate), but has been polluted with a lot of “non-actionable” events (e.g. user input could not be processed – expecting the user to try again, nothing for devops to do).

What are some options for going from a system full of mixed good and bad event data, to a clean system with only good data so that the alerts become meaningful again and don’t get ignored?

Examples: 1) Gradually work through each event, starting with the low hanging fruit/most common events, deciding whether or not it’s actionable. 2) Create a new system and gradually transfer actionable events to it.

How to combine Mac terminal find -name patterns?

I use Xcode. I want to use bash to batch modify the UI fonts.

Here is the code to “.xib” and “.storyboard”:

xibd(){      cd "$  (dirname "$  1")/.." && pwd      find . -type f -name "*.xib"  -exec  sed -i '' s/'\<fontDescription key=\"fontDescription\" type=\"system\" pointSize=\"17\"\/\>'/'\<fontDescription key=\"fontDescription\" name=\"PingFangSC-Regular\" family=\"PingFang SC\" pointSize=\"12\"\/\>'/ {} +       find . -type f -name "*.storyboard"  -exec  sed -i '' s/'\<fontDescription key=\"fontDescription\" type=\"system\" pointSize=\"17\"\/\>'/'\<fontDescription key=\"fontDescription\" name=\"PingFangSC-Regular\" family=\"PingFang SC\" pointSize=\"12\"\/\>'/ {} +  } 

I want to combine -name “.storyboard” and -name “.xib”, how to achieve it?

I tried

find . -type f -name '*.storyboard'  -o  -name  "*.xib"  -exec  sed -i '' s/'\<fontDescription key=\"fontDescription\" type=\"system\" pointSize=\"17\"\/\>'/'\<fontDescription key=\"fontDescription\" name=\"PingFangSC-Regular\" family=\"PingFang SC\" pointSize=\"12\"\/\>'/ {} +   find . -type f -name "*.xib|storyboard"  -exec  sed -i '' s/'\<fontDescription key=\"fontDescription\" type=\"system\" pointSize=\"17\"\/\>'/'\<fontDescription key=\"fontDescription\" name=\"PingFangSC-Regular\" family=\"PingFang SC\" pointSize=\"12\"\/\>'/ {} + 

it does not work.

I have read the related of man find. Still working on it.

Design patterns for migrating a legacy database model

I have a product which has a un-normalized legacy data model which contain millions of records. This has cause problems when adding new features and with performance. Also this contributes to high storage requirements at data file level on databases. I’m looking into a finding some good patterns which i can follow to migrate my data from this current legacy data model to a more normalize modern data model. Are there any good patterns which i can make use of ?

How to identify patterns from users survey comments

I have conducted an online survey where 1500 users participated. They have their opinions and comments about particular problems. I am trying to consolidate all their opinions & pulling out patterns from their comments. It is not easy to read through all 1500 comments and create pattern quickly for a single person.

Is there any recommended method which can help me analyze 1500 comments and draw couple of patterns out of these comments?

Remembering what chores to to each day with LED patterns

I am using a Raspberry Pi 3 model b to control LEDs connected on a breadboard. I want the lights to tell me what chore I have to do today. When to take out the trash, recyclables, vacuum, and clean the bathroom. There’s is also another rotation happening every 6 days that I need to keep track of. The code does run and fulfill its purpose, but it is really inconvenient that I have to rewrite the functions Fixed(), vacuum(), and chores() to have the code start in the position I want. My question is how can I make the code run in the right starting position of the cycles with only inputs without having to rewrite sections?

#!/usr/bin/python # -*- coding: utf-8 -*-  "By Andre Akue"  import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setwarnings(True) import time import datetime from os import system from multiprocessing import Process  speed = 2 #blinking speed day_duration = 60*60*24 check_time = 600 #check for day change every 600 secs  class lights: #setting up leds      def __init__(self,color_name,color_pin):         self.name = color_name         self.pin = color_pin         GPIO.setup(self.pin, GPIO.OUT, initial = 0)      def solid(self):#stay on when it's the first day or when the trash is being collected the next day (warning)         GPIO.output(self.pin,1)         time.sleep(check_time)         GPIO.output(self.pin,0)      def flash(self): #blink when it's the second day or when the trash is being collected         stp = time.time() ; etp = time.time() + check_time # stp/etp = starting / ending time pattern         while time.time() < etp:             GPIO.output(self.pin,0)             time.sleep(0.8/speed)             GPIO.output(self.pin,1)             time.sleep(0.2/speed)             GPIO.output(self.pin,0)  L1 = lights("white", 21) L2 = lights("yellow", 16) L3 = lights("red", 12) L4 = lights("blue", 25) L5 = lights("green", 24) L6 = lights("snow", 23)  def chores():#a 6 day cycle divided into 3 steps of 2 days each     while 1:     #Sweeping the floor - First Day         L2.solid()#yellow stays on     #Sweeping the floor - Second Day         L2.flash()#yellow keeps blinking     #Setting the table - First Day         L3.solid()#red stays on     #Setting the table - Second Day         L3.flash()#red keeps blinking     #Washing dishes - First Day         GPIO.output((L2.pin,L3.pin),1)#red and yellow stay on         time.sleep(check_time)         GPIO.output((L2.pin,L3.pin),0)     #Washing dishes - Second Day         stp = time.time() ; etp = time.time() + check_time # stp/etp = starting / ending time pattern         while time.time() < etp:#red and yellow keep blinking             GPIO.output((L2.pin,L3.pin),0)             time.sleep(0.8/speed)             GPIO.output((L2.pin,L3.pin),1)             time.sleep(0.2/speed)             GPIO.output((L2.pin,L3.pin),0)  def log():# print weekday and day count in command prompt     count = 0     while 1:         for day in week_order:             count += 1             print ('\nDay: %s\t\tDay of the week: %i' % (day,count))             time.sleep(day_duration)  def vacuum():     while 1:     #only happens Friday to Sunday every 3 weeks         for day in list(range(1,22)):             if day not in [4,5,6]:                 time.sleep(day_duration)             elif day == 4:                 L5.solid()             elif day == 5:                 L5.solid()             elif day == 6:                 L5.flash()    def start_tomorrow(): #cycle starts the day after the code has been started     tomorrow = datetime.datetime.now() + datetime.timedelta(days=1)     while datetime.datetime.now() < tomorrow:         time.sleep(60)         print ('\nchore cycle started')  def fixed(): #all weekly, fixed items     while 1:         if datetime.datetime.now().strftime('%a') == 'Mon':             L1.flash()#trash             L6.solid()#recycle         elif datetime.datetime.now().strftime('%a') == 'Tue':             L6.flash()#recycle         elif datetime.datetime.now().strftime('%a') == 'Wed':             L1.solid()#trash             L4.solid()#bath         elif datetime.datetime.now().strftime('%a') == 'Thu':             L1.flash()#trash             L4.flash()#bath         elif datetime.datetime.now().strftime('%a') == 'Fri':          elif datetime.datetime.now().strftime('%a') == 'Sat':          elif datetime.datetime.now().strftime('%a') == 'Sun':             L1.solid()#trash  try:#using processes so that different cycles can run independently     if __name__ == '__main__':         Process(target=log).start()         Process(target=chores).start()         Process(target=bath).start()         Process(target=recycle).start()         Process(target=vacuum).start()         Process(target=trash).start()  except KeyboardInterrupt:     system('clear')     print ("\n\n\texited via keyboard interrupt\n\n")     GPIO.cleanup()  #when resetting: #3-chore cycle #   place the chore happening tomorrow in first place in the sequence  #'bath','trash','recycle', and 'log' #   place tomorrow in first in the list of weekdays #   'week_order'  #vaccum cycle #   count the number of days till the next 'first vacuum day', #   and start with this number in the list of the "if" loops