Deciding which microservice should write to the database

Let’s assume the following architecture where

  1. EventCreatorApp creates an Event which is logged to DB and sent to WorkerApp for processing
  2. WorkerApp processes the event, handles failures, etc.
EventCreatorApp --> [ DB ]         |          ---------> WorkerApp 

Once WorkerApp is done, I want to update the event row in the DB with the outcome of running that event.

My question: Which app should write the outcome to the database?

If WorkerApp writes the outcome to the db the logic is nicely decoupled (one app creates events, one app executes events) but I have two apps writing to the db. What’s worst, I want to deploy WorkerApp on an AWS Lambda, and that would mean opening a new connection to the db for each event processed.

If EventCreatorApp writes the outcome to the db I don’t have any db access problems, but it feels like I’m pushing into EventCreatorApp some logic that doesn’t really belong there, and in general I’m coupling the two apps a bit since EventCreatorApp would have to wait for a response.

Which solution is best?

I can help you write professional SEO articles. for $36

I Will Write A 500-3000 Word Mind Blowing SEO Blog Article. Successful blog articles use premium content to engage, educate, create consumers loyalty, and, establishes you as the authority in your niche. The result is increased exposure and an abundance of sales. How well do your current blog articles do that?I am guessing not well, which is where I come in. My promise to you: I will create a 100% original, high quality, well-researched blog article to help you attract and engage your demographic on a regular basis. You Get: ✏️ All work is fact-checked and copy-edited ✏️ A professionally written SEO optimized article that follows SEMrush’s ranking guidelines. ✏️ Persuasive and engaging language that grabs the readers’ attention ✏️ Thoroughly researched content to build you as an authority, including links to high-quality sources to back up facts and point to resources

by: yoyoli
Created: —
Category: Content & Writing
Viewed: 6


How to write a database class in python? [on hold]

I’m a database beginner and I want to know how to turn my “database code” into a real python class. Because I have a little bit of experience in OOP I’m actually not feeling very well calling that my database and sadly I do not now how to approach this problem. Literature on that topic would be appreciated to get my mind around databases and database design.

import pymysql as PyMySQLdb  conn = PyMySQLdb.connect('localhost', 'schema', 'superdupersecretpassword', 'fvt') db = conn.cursor(PyMySQLdb.cursors.Cursor) 

How do I write unit tests for legacy code (that I don’t understand)?


Forward

I’ve read a lot of things before asking this question, including many relevant questions right here on SE:

  • (Software Engineering SE) Writing tests for code whose purpose I don’t understand
  • (Software Engineering SE) Unit testing newbie team needs to unit test
  • (Software Engineering SE) Best practices for retrofitting legacy code with automated tests
  • (Software Engineering SE) How to unit test large legacy systems?
  • (Blog post) How to mock up your Unit Test environment

However, I can’t help but feel that the itch hasn’t been scratched yet after reading for help.


TL;DR

How do I write unit tests for legacy code that I can’t run, simulate, read about, or easily understand? What regression tests are useful to a component that presumably works as intended?


The Whole Picture

I’m a returning summer intern again as I’m transitioning into grad school. My tasking involves these requirements:

  1. For a particular product, evaluate whether our software team can upgrade their IDE and JUnit version without losing compatibility with their existing projects.
  2. Develop unit tests for some component in the existing Java code (it’s largely not Java). We want to convince the software team that unit testing and TDD are invaluable tools that they should be using. (There’s currently 0% code coverage.)
  3. Somehow, end the days of cowboy coding for a critical system.

After obtaining a copy of the source code, I tried to build and run it, so that I might understand what this product does and how it works. I couldn’t. I asked my supervisors how I do, and I was issued a new standalone machine capable of building it, including the build scripts that actually do. That didn’t work either because as they should’ve expected, their production code only runs on the embedded system it’s designed for. However, they have a simulator for this purpose, so they obtained the simulator and put it on this machine for me. The simulator didn’t work either. Instead, I finally received a printout of a GUI for a particular screen. They also don’t have code comments anywhere within the 700,000+ Java LOC, making it even harder to grasp. Furthermore, there were issues evaluating whether or not their projects were compatible with newer IDEs. Particularly, their code didn’t load properly into the very IDE version they use.

My inventory is looking like this:

  • NetBeans 8, 9, 10, 11
  • JUnit 4, 5
  • Their source code for a particular product (includes 700,000+ Java LOC)
  • Virtually no code comments (occasionally a signature)
  • No existing tests
  • A physical photo of a GUI window
  • A software design document (109 p.) that doesn’t discuss the component in the picture

I at least have enough to theoretically write tests that can execute. So, I tried a basic unit test on this said component. However, I couldn’t initialize the objects that it had as dependencies, which included models, managers, and DB connections. I don’t have much JUnit experience beyond basic unit testing, so follow me to the next section.


What I’ve Learned From My Reading

  1. Mocking: If I write a unit test, it likely needs to have mock variables for production dependencies that I can’t easily initialize in setUp.
  2. Everyone here liberally suggests the book “Working Effectively with Legacy Code” by Michael Feathers.
  3. Regression tests are probably a good place to start. I don’t think I have enough weaponry to attempt integration testing, and regression tests would provide more instant gratification to our software team. However, I don’t have access to their known bugs; but, I could possibly ask.

And now an attempt to articulate the uncertainty I still have as a question. Essentially, I don’t understand the how part of writing these tests. Assuming I don’t receive any further guidance from my supervisors (likely), it’s in my ballpark to not only learn what this component does but to decide what tests are actually useful as regression tests.

As professionals who’ve worked with projects like this longer than I have, can you offer any guidance on how to write unit tests in this kind of situation?

Samsung Galaxy S6 4.6MB/s Seqential Write (Why so slow?)

I bought a Samsung Galaxy S6 in Aug 2016. Everything was fine, until last week. It got very slow. For example, when I draw my unlock pattern after a reboot, it takes such a long time to load the homescreen that the screen turns off. After a few tries, I get in but every tap takes very long until the device reacts. It takes ~25 seconds just to load the keyboard.

I downloaded System Monitor but the CPU load was not on 100%, so there is no app/virus which consumes too much CPU time. Geekbench 4 says that the CPU / GPU performance is even above average for the Galaxy S6.

But then I decided to test the storage speed. I ran Androbench and the results are very bad (see screenshot). Screenshot of Androbench

Normally, the performance should be like in this test.

So my questions now are: how can I find out why is the storage so slow? Is it just flash wear? Is is a broken driver? If it’s a hardware failure, what part do I have to replace?

If something is unclear, just comment and I will edit the question. Thank you in advance!

Is it ok to allow a web application to write its own executable files?

Usually I setup my Ubuntu server to have at least 2 users:

  • A user behalf which the web server (Apache or Nginx) runs, e.g. www-data in group www-data
  • A user that updates and maintains the web applications, e.g. deployer in groups deployer and www-data

A web application consists of 2 directories:

  • A directory for executable files (e.g. PHP or JS) served by the web server (Apache or Nginx) and a code interpreter, e.g. app
  • A directory for the application to write (caches, logs, uploads, etc.), e.g. storage

I make make the app directory have rwxrwxr-x deployer:deployer (mode, user and group) permission and storage have rwxrwxr-x www-data:www-data permission.

The problem is that it’s inconvenient to maintain the web application because it writes the files to storage with the default permission (rw-r--r-- www-data:www-data) and therefore deployer can’t write them. And vise versa, deployer can leave files in storage with rw-r--r-- deployer:deployer permission that are not writable by the application. I have to make some complex sudo setup and watch carefully the files created by deployer creates to maintain the application and keep it running.

Does the application self-write restriction worth the inconveniences? Is it ok (considering security concerns) to run the web server and maintain the application using a single user that can write the files both in the app and storage directories?

how to write hive queries for following problems

i have a table with 10 columns ColumnNo Name Example DataType

Column1 athlete_name Michael Phelps STRING

Column2 age 23 INT Column3 country United States STRING

Column4 year 2008 INT

Column5 closing_date 8/24/2008 STRING

Column6 sport Swimming STRING

Column7 gold_medals 8 INT

Column8 silver_medals 0 INT

Column9 bronze_medals 0 INT

Column10 total_medals 8 INT

i have few queries to write

Find out the total number of medals won by each country in swimming  Find out the total number of medals won by India in each year  Find out the total number of medals won by each country and also display the name of the country  Find out the total number of gold medals won by each country  Find out the country got medals for Shooting for each year

I’ll write compelling quality content, article writing and blog post of 1000 words for your website for $5

What do you need to know about this service? When it comes to blog writing, I do my research and add my usual flair to address your particular audience. Not only can i nail that title and opening paragraph, but also optimize content to keep your readers engaged until the last word. I will implement optimized titles, targeted keywords,a good radio and more to ensure search engines like the article as much as your readers will. What are you likely to get out of the service? Refined writing.No grammatical errors guaranteed.Audience focus with a sense of adventure to provoke curiosity.Incorporation of your unique brand,products or services.Most importantly, an unforgettable reading experience.What are you waiting for? Let’s get writing……………………….

by: eddiemur25
Created: —
Category: Content & Writing
Viewed: 116