17

78 Node.js Interview Questions & Answers

 4 years ago
source link: https://coderrocketfuel.com/article/node-js-interview-questions-and-answers
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Introduction

Do you have a Node.js interview coming up?

You should prepare for a wide range of potential questions regarding Node.js directly and anything related to JavaScript or general programming architecture topics.

To help you out with this, we've created a huge list of questions and answers to help you prepare for things you may be asked.

1. What is Node.js?

Node.js is a JavaScript platform/runtime built on Google Chrome's JavaScript V8 engine . This allows JavaScript to be used on machines outside of a browser and allows developers to use JavaScript to write things like command-line tools and server-side scripts.

As a result, Node.js represents the JavaScript everywhere paradigm by unifying web application development around a single programming language, rather than different languages being used on the server and client-side.

2. What is Node.js used for?

Due to the fact that Node.js is single-threaded , Node.js is usually used for non-blocking and event-driven servers.

This makes it great for building things like static file servers, web application frameworks, REST APIs, messaging middleware, real-time services (chat, games, etc), command-line applications, browser games, and anything else that isn't CPU intensive or doesn't require long processing times.

Amongst those use-cases, web applications are the most commonly used by developers .

3. What language is Node.js written in?

Node.js works by using the V8 engine to compile JavaScript into native machine code during runtime. The V8 engine is written in C++ and Node.js also uses bindings written in C++ that connect JavaScript to the V8 engine.

4. Who was the original author/creator of Node.js? And who works on Node.js now?

Node.js was initially created by Ryan Dahl in 2009 and was sponsored by Joyent . Today, Node.js is maintained and built by open-source software developers.

5. What are the key features of Node.js?

V8

Since Node.js compiles JavaScript to machine code using the V8 engine, it allows for high runtime performance.

Single-Threaded Execution

Node.js runs on a single-threaded event loop model. Therefore, it can handle multiple concurrent connections without creating more than one thread. This gets rid of the performance costs associated with thread context switching and can prevent any errors caused by synchronizing multiple threads (this can be hard to troubleshoot).

Asynchronous

Multiple requests to Node.js can be handled without having any dependency on each other, which boosts both throughput and efficiency.

Rich Ecosystem Provided By NPM

The Node Package Manager (NPM) is a command-line utility included by default with Node.js. And it also provides a huge online repository of open-source code to choose from. NPM allows you to search, install, share, and reuse lines of code.

Full Stack JavaScript Development

Node.js made it possible for developers to use JavaScript on the server-side. Now, they can use the same scripting language on both the frontend and backed when they build applications. This allows developers to build things faster and reduces the size of the learning curve.

6. What are some of the drawbacks with of Node.js?

The main drawback is that it's not efficient when handling CPU-intensive tasks or any long-running operations. Examples of these types of tasks include generating audio and video or editing graphics.

7. What's the name of the JavaScript engine Node.js is built on?

The V8 engine.

8. How does the V8 engine work?

V8 compiles and executes JavaScript source code into machine code, handles memory allocation for objects, and garbage collects objects it no longer needs. V8 enables any C++ application to expose its own objects and functions to JavaScript code.

9. What is the event loop in Node.js?

The event loop is what allows Node.js to perform non-blocking Input/Output operations (even though JavaScript runs on a single thread) by offloading operations to the system kernel whenever possible.

The main role of the event loop is to schedule which operations the single thread should be performing at any given point in time.

For more information on how the event loop works.

Another great source for further reading.

10. What is libuv?

libuv is a multi-platform support library with a focus on asynchronous I/O. It was primarily developed for use by Node.js, but it’s also used by Luvit, Julia, pyuv, and others.

It is used by the V8 engine to perform I/O for network and file operations.

Check out the libuv documentation for more information.

11. How does Node.js handle child threads?

By default, Node.js runs on a single-thread and leaves it up to developers to spawn their own child processes using the child_process module.

Check out the Node.js documentation for more information.

12. What is the difference between synchronous and asynchronous programming?

When you execute code synchronously , you wait for it to finish before moving to another task.

When you execute code asynchronously , you can move on to another task before it finishes.

13. Why is asynchronous programming important in Node.js?

User interfaces are asynchronous by nature, in that they spend the majority of their time waiting for the user to interrupt the event loop and trigger event handlers.

Therefore, Node.js is also asynchronous by default and the server works in the same way. It waits for a request from the network and can accept additional incoming requests while the first one is handled. This is very beneficial to performance on the server.

14. How do you handle errors when dealing with asynchronous code?

You can use a try...catch statement to help with error handling asynchronous code.

The code looks similar to this:

Node.js

try {

// your code here

} catch (e) {

console . error (e)

}

15. Why is some code considered to be "blocking"?

Blocking code is when the execution of additional JavaScript in the Node.js process must wait until a non-JavaScript operation completes. This happens because the event loop is unable to continue running JavaScript while a blocking operation is occurring.

Blocking methods execute synchronously and non-blocking methods execute asynchronously .

Source

16. What is process.nextTick() used for?

In Node.js, each iteration of the event loop is called a tick . The process.nextTick() method is used to defer the execution of a function until the next iteration in the Node.js event loop.

You can pass a function to the process.nextTick() like this:

Node.js

process . nextTick (() => {

// do something here

}

This tells the Node.js engine to call that function at the end of the current operation and before the next event loop tick starts.

17. What is event-driven programming?

Event-driven programming is a paradigm in which the flow of the program is determined by events like user actions (clicks or keypresses) or messages from other programs. In an event-driven application, there's usually a main loop that listens for certain events and triggers a callback function one of the events is received.

18. What is the EventEmitter in Node.js?

The EventEmitter is a module that facilitates communication/interaction between objects in Node. Emitter objects emit named events that cause previously created listeners to be called when they detect the named event. It works similar to how a pub/sub or observer design patter does.

Check out the Node.js documentation for more information.

19. Can you create an HTTP server using Node.js? If so, can you explain the code needed to do so?

Yes, you can certainly create an HTTP server using Node.js.

Here is what a basic HTTP server would look like in code:

Node.js

const http = require ( "http" )

http . createServer ( function (req, res) {

res . writeHead ( 200 , { "Content-Type" : "text/plain" })

res . write ( "Hello World!" )

res . end ()

}). listen ( 8080 )

For more information on the HTTP module in the Node.js documentation.

20. What is a control flow function?

The control flow is the order in which the computer executes statements in a script. A control flow function is one that handles or modifies the sequence in which different pieces of code runs.

21. Does Node.js support multi-core computing platforms? Is it capable of utilizing more than one CPU core?

It does not do so by default. But you can use the Cluster module to launch a cluster of Node.js processes on multiple processes.

You can also control the number of Node.js processes created by the Cluster module and match it with how many CPU cores a machine has.

Check out our article on how to create the code to do this.

22. Describe what a stream is in Node.js?

In Node.js, a stream is an abstract interface for working with Unix pipes that read data from a source and pipe it to a destination.

For example, in a Node.js based HTTP server, the request is a readable stream and the response is a writable stream. Another example can be found with the fs module, which lets you work with both readable and writable file streams.

23. How many types of streams exist in Node.js?

Three are four different types of streams in Node.js.

  • Writable :  streams to which data can be written to
  • Readable :  streams from which data can be read from
  • Duplex :  streams that are both Writable and Readable
  • Transform :  Duplex streams that can modify the data as it's written or read

24. What kind of events can be fired by a stream?

Each type of stream in Node.js is an EventEmitter instance and can throw several types of events at different times.

These are the commonly used ones:

  • data :  fired whenever data is available to be read
  • end :  fired when there is no more data to be read
  • error :  fired when there is an error when receiving or writing data
  • finish :  fired when all the data has been flushed to the underlying system

25. What's the difference between readFile() and createReadStream() in Node.js?

The readFile() function will read a file completely into memory before making it available to the user.

And the createReadStream() function reads the file in chunks of the size specified beforehand.

The createReadStream() function will scale better when dealing with larger files or when lots of requests are occurring at the same time.

26. What general practices do you use for debugging when building Node.js applications?

For this question, explain some debugging methods you have used in the past. These may be specific to you, but you can talk about some general topics such as these:

The Built-In Debugger

The Node.js debugger is a built-in way to debug an application. It exposes a debugger statement that you can place in your source code to cause your code to break at certain points. You must run your Node.js application in debug mode for this to work ( node debug your-app ).

It would look similar to this in your code:

Node.js

setTimeout (() => {

debugger

console . log ( "world" )

}, 1000 )

console . log ( "hello" )

When you run that code with the debug flag, it will expose a command-line interface that allows you to inspect your code.

Node Inspector

The Node Inspector is an NPM package that provides a debugger interface for Node.js applications.

You can talk about using this tool or one of the many others for debugging.

Creating Tests

By creating extensive tests for your application, you will form a great understanding of how your application works and it will make the process of finding bugs easier when they occur.

27. What keyword can you insert into your code to act as a debug breakpoint?

The Node.js debugger is a built-in way to debug an application. It exposes a debugger statement that you can place in your source code to cause your code to break at certain points. You must run your Node.js application in debug mode for this to work ( node debug your-app ).

It would look similar to this in your code:

Node.js

setTimeout (() => {

debugger

console . log ( "world" )

}, 1000 )

console . log ( "hello" )

When you run that code with the debug flag, it will expose a command-line interface that allows you to inspect your code.

28. What's the difference between programmer and operational errors?

Operational Errors

Operational errors are run-time problems experienced by correctly-written programs. These are not necessarily bugs in the program and are usually problems caused by something with the system itself, the system's configuration, the network, or a remote service.

Some specific examples include:

  • failed to connect to server
  • failed to resolve hostname
  • server returned a 500 response
  • system is out of memory

Programmer Errors

Programmer errors are bugs in the program and are caused by the developer. These are things that can be fixed by changing the code.

29. What are callbacks used for in Node.js?

Node.js APIs make heavy use of callback functions. A callback is a function passed as an argument to another function that will be called when the function ends. It is an asynchronous equivalent for a function and is called at the completion of a given task.

30. What is callback hell?

Callback hell is a JavaScript anti-pattern caused by deeply nested asynchronous functions. Callback hell happens when you have callbacks within callbacks within callbacks and your code becomes difficult if not impossible to reason about.

31. How do you prevent or fix callback hell?

There are a lot of ways to prevent or fix callback hell. You can keep your code shallow and modularize sections of your code into pieces where a risk of callback hell exists.

32. What is the first argument passed to a Node.js callback function?

The error object.

If an error occurred, it will be returned by the first err argument. And the second argument of the callback is usually reserved for successful response data.

33. What is a Promise?

A promise is an object that may produce a single value at some point in the future. That value can be either a resolved value or a reason for why it wasn't resolved (an error).

A promise can be in three different states:

  1. pending
  2. fulfilled
  3. rejected

Callbacks can be attached to the promise to handle the fulfilled value or any rejection reasons.

For more information.

34. What is NPM?

NPM stands for Node.js Package Manager and is the default package manager for Node.js.

35. What functionalities does NPM provide when building Node.js applications?

NPM consists of a command-line client and an online database of public and paid private packages called the NPM registry. The registry is accessed via the client, and the available packages can be browsed and searched via the NPM website .

36. What's the difference between NPM packages and Node.js core modules?

Node.js core modules provide the bare minimum functionalities of Node.js. They are compiled into the binary distribution of Node.js and load automatically when the Node.js process starts. Therefore, they can be imported directly into your Node.js code without installing anything.

On the other hand, NPM packages is code that can be imported into a Node.js application via the NPM registry. These need to be installed via the NPM command-line utility.

37. What is a global installation of a NPM dependency?

An NPM dependency that is installed globally on your machine will be stored in the /npm directory and will be available for use via the command line anywhere on your machine.

But, you won't be able to import global packages into a Node.js application directly.

You can install Node.js packages globally by adding the -g flag to the npm install command.

38. What is a local dependency of a NPM dependency?

NPM packages installed locally will be installed to the node_modules directory for a given Node.js application. These packages can be imported directly into the Node.js application is was installed for.

This is the default behavior for installing NPM packages and, therefore, you don't need to add any flags to the npm install command.

39. How do you update NPM to a new version in Node.js?

You can update NPM to the latest version by using this command: npm install -g npm@latest .

40. What is the most popular alternative to NPM? What are its benefits?

Yarn is a popular alternative to NPM.

Many have reported that Yarn provides much faster installation times compared to NPM due to it's caching mechanisms. And it also makes security a core value by using checksums to verify the integrity of every installed package before its code is executed.

41. What's a package.json file? And what is it used for?

The package.json file holds the various metadata relevant to a Node.js project. It gives information to NPM that allows it to identify the project as well as handle its dependencies.

It can also hold other types of metadata such as a project description, the version of the project, license information, and even configuration data. It is usually stored in the root directory of the Node.js application.

42. What's a package-lock.json file? And why is it used?

The package-lock.json file is automatically generated for any operations where NPM modifies either the node_modules directory or the package.json file. It describes the exact tree that was generated, such that subsequent installs can generate identical trees, regardless of intermediate dependency updates.

It serves several purposes:

node_modules

Source

43. How do you update a dependency using NPM?

You can update one or multiple NPM dependencies using the npm update app-name command.

44. What's the difference between a dependency and a devDependency in the package.json file?

The devDependencies are modules that are only required during the development process. And dependencies are modules that are required at runtime.

45. What are exit codes in Node.js?

Node.js will normally exit with a 0 status code when no more async operations are pending. There are other codes used in different circumstances.

Some examples include:

  • 1 - Uncaught Fatal Exception : There was an uncaught exception, and it was not handled by a domain or an event handler
  • 3 - Internal JavaScript Parse Error : The JavaScript source code internal in Node's bootstrapping process caused a parse error
  • 4 - Internal JavaScript Evaluation Failure : The JavaScript source code internal in Node's bootstrapping process failed to return a function value when evaluated

Source

46. What is REPL in Node.js?

Node.js comes with a virtual machine called REPL, which is also called the Node shell. REPL stands for Read-Eval-Print-Loop and the virtual environment can be used as a quick and easy way to test simple Node.js code.

47. What's piping in Node.js?

In Node.js, piping is used when dealing with streams. And is the name for the method used to connect a readable stream to a writeable stream. This is a common method when dealing with file streams using the stream.pipe function.

For more information.

48. What's the purpose of the Buffer class in Node.js?

Buffers are used for reading or manipulating binary data while it's in the process of being streamed. The Buffer class was introduced as part of the Node.js API to make it possible to interact with octet streams in the context of things like TCP streams and file system operations.

Check out the Node.js documentation for more information.

49. Why is it important to maintain a consistent coding style across a Node.js project?

Inconsistent code can cause problems if your code is very interconnected with legacy code or if it's part of a much large library. And it could also cause problems if a lot of people work on your codebase and, therefore, many different people need to understand it and work on it.

Maintaining a consistent coding styling will help mitigate any of those potential problems.

50. What tools can be used to assure it?

You can use JavaScript IDE's like VS Code that will help you format your code by default. And you can also use packages like ESLint that let you configure a set of formatting rules for your code and enforces them during testing and deployment processes.

51. What purpose does a .env file serve?

The .env file is used for storing any environment variables used for a Node.js project.

Environment variables are used to store sensitive information like API keys and passwords and can be used to easily handle those variables globally across an entire Node.js application.

The .env file is usually stored in the root directory for an application and shouldn't be committed to the source code repository because it often contains sensitive information like passwords and usernames.

52. What are the differences between the setTimeout() & setInterval() functions?

setTimeout()

The setTimeout() function lets you run a function once after an interval of time has elapsed (specified by the developer)

Here's a code example:

Node.js

setTimeout (() => {

console . log ( "Hello!" )

}, 1000 )

The message will be logged after the 1000 milliseconds time interval has elapsed.

setInterval()

The setInterval() function lets you run a function repeatedly, starting after an interval of time has elapsed (specified by the developer), and then repeating continuously at that interval

Here's a code example:

Node.js

setInterval (() => {

console . log ( "Hello!" )

}, 1000 )

This will first wait for 1000 milliseconds and then log the message after every subsequent 1000 milliseconds have passed.

53. How do you create a directory using Node.js?

Node.js has an Fs core module that provides an fs.mkdir() function that makes creating a new directory or folder an easy process.

The code would look something like this:

Node.js

const fs = require ( "fs" )

fs . mkdir ( "./new-directory-name" , function(err) {

if (err) {

console . log (err)

} else {

console . log ( "New directory successfully created." )

}

})

That function would result in a new directory called new-directory-name being created.

For more information.

54. How do you delete a directory?

Node.js has an Fs core module that provides an fs.rmdir() function that allows you to delete an empty directory.

If you want to delete a directory that contains files or other sub-directories, you'll need to recursively go through and remove all the individual files first. There are NPM packages that handle this for you, such as rimraf .

Here is how you'd implement it yourself.

55. How would you read the contents of a directory?

Node.js has an Fs core module that provides an fs.readdir() function that makes it easy to read the contents of a specified directory.

It would be used in your code like this:

const path = require ( "path" )

const fs = require ( "fs" )

const directoryPath = path . join ( __dirname , "files" )

fs . readdir (directoryPath, function (err, files) {

if (err) {

console . log ( "Error getting directory information." )

} else {

files . forEach ( function (file) {

console . log (file)

})

}

})

For more information on how to implement this.

56. What is the preferred method of solving unhandled exceptions in Node.js?

Good practice suggests that you should use the Process. Process is a global object that provides information about the current Node.js process that is being used by your application. And it is also a listener function that listens for certain events to occur.

Some of those events include:

  • exit
  • disconnect
  • uncaughtException
  • rejectionHandled

You can write your own code to detect when the unhandledException event has been fired and handle the error safely:

Node.js

process . on ( "uncaughtException" , function (err) {

// handle the error

console . log (err)

})

For more information, check out the Node.js documentation.

57. Can you name a couple of programming paradigms that are important for Node.js developers?

Two important programming paradigms:

  1. Functional Programming
  2. Object-Oriented Programming

58. Can you describe what functional programming is?

Functional Programming is a programming paradigm where you structure your code using mostly functions. Said functions take inputs (called arguments) and show the output based on those inputs provided to the function.

It also doesn't allow any mutation or shared state and the functions are intended to stay pure to their expression and avoid side-effects.

Examples of functional programming languages include Lisp, Haskell, Erlang, Clojure, and Elm.

Some features of the functional programming language include first-class citizen functions , higher-order functions , and function composition .

The main benefit of using functional programming is that it doesn't involve a lot of side-effects and is immutable, which reduces the chances that your code will create hard to track down bugs. And your code will be more clean, straightforward, and succinct.

59. What is object-oriented programming?

Object-oriented programming is a coding paradigm where you use objects to model real-world things that you want to represent inside your application. And it provides a simple way to access functionality that would otherwise be hard or impossible to make use of.

Check out the MDN web docs for more information.

60. What are the pros and cons between these two paradigms: functional programming and object-oriented programming?

Object-Oriented Programming

Pros:

  • The basic concepts behind objects and method calls are easy to understand for developers
  • The imperative style (rather than declarative ) reads like a more straight forward set of instructions for the computer to follow

Cons:

  • Objects and behaviors are tacked together to the same entity and often use a shared state. This means they can be accessed at random by other functions in a non-deterministic order, which could lead to undesirable behavior such as race conditions

Function Programming

Pros:

  • In the functional paradigm, sharing state and/or side-effects is avoided. This eliminates the potential for bugs to arise from the same functions using the same resources
  • Programs that use pure functions are typically easier to scale to multiple additional processors or across distributed clusters without race condition or threading resource issues
  • Functional programming usually uses the declarative style, which does not give step-by-step instructions for operations. They instead focus on what to do and let the underlying functions figure out how to do it. This leaves a lot of room for refactoring and performance optimization.

Cons:

  • Using functional programming styles in your code too much can potentially lead to reduced readability because the resulting code is often abstract, more terse, and less concrete
  • More people are familiar with the object-oriented programming style, so common ideas in functional programming may be confusing to new teammates

Source

61. What is a pure function?

Pure functions don't produce any side-effects and can't alter any state external from itself. Given the same input, they should always return the same output.

Not every function can be pure, but its often a good choice when they can be.

For more information.

62. What is function composition?

Function composition is the process of combining more than one function to produce a new function.

For more information.

63. What's the difference between the two types of inheritance: prototypal & classical?

Classical Inheritance

These inherent from a class and create sub-class relationships called hierarchical class taxonomies. Instances are usually created using a constructor function with the new keyword.

Class inheritance might or might not use the class keyword from ES6.

Prototypal Inheritance

These inherit directly from another object and are usually created using factory functions or the Object.create() method. Instances can be composed of many different methods.

64. What is a Closure?

A closure is a combination of a function enclosed with references to its surrounding state. Further, a closure gives you access to the outer function's scope from an inner function. They are created every time a function is created.

Closures are important because they control what is and isn’t in scope in a particular function, along with which variables are shared between sibling functions in the same containing scope. Understanding how variables and functions relate to each other is important in understanding how your code works.

You can use a closure by defining a function inside another one and then expose it by returning or passing it to another function. The inner function will then have access to the variables in the outer function scope.

For more information.

65. What are some common uses for closures?

You can use closure for data privacy, where the enclosed variables are only in scope within the containing function.

Also, you can use them to create stateful functions whose return values can be influenced by their internal state.

66. What's Git used for?

Git is a free and open-source distributed version control system.

In other words, it's an application that keeps track of your code and all the changes that have been made to it in the past. Also, it allows you to share your code with others and collaborate on it without overwriting each other's changes.

A complete introduction to Git.

67. What's a reverse proxy?

A reverse proxy is a type of web server that takes requests, forwards them to another HTTP server somewhere else, receives a reply, and then forwards the data to the original requestor.

68. What are the benefits of using a reverse-proxy (with Nginx or Apache) for a Node.js application?

There are several benefits:

  • SSL termination : Handling SSL termination (changing HTTP to HTTPS) directly in your Node.js app can be tedious and expose security risks. When only a reverse-proxy is allowed to perform SSL termination, only the reverse proxy has access to the SSL certificate. Without a reverse proxy, all the code in your application (including 3rd party modules) will have access to your certificates.
  • Clustering : Node.js comes with it's built-in Cluster modules which can run applications on more than one process.
  • Gzip compression : Off-loading gzip compression from your application to the reverse proxy can allow you to have the same compression logic at the organization level, instead of having to configure it for each application.
  • Performance benefits : SSL encryption, clustering, and gzip compression are high CPU-bound operations. Dedicated reverse proxy tools (like Nginx) usually perform those tasks faster than Node.js.
  • Simplified application code : Using a reverse proxy allows your application to focus on business logic and not about protocols and process management. As a result, your code will be simplified greatly.

More information.

69. What's the difference between SQL & NoSQL databases?

  • SQL : a relational database management system, is vertical scalable, has fixed schema, is not suitable for hierarchical data storage, and can be used for complex queries.
  • NoSQL : a distributed database management system, horizontally scalable, has a dynamic schema, is best suitable for hierarchical data storage, and is not good for complex queries.

70. What's the difference between declaring a variable with const, var, or let?

  • let : means the variable may be reassigned (used for things like a counter in a loop or a value swap in an algorithm)
  • const : means that the identifier can't and won't be reassigned
  • var : means that the variable may or may not be reassigned and it may or may not be used for an entire function

For more information.

71. What's the difference between the null, undefined, and undeclared variable values?

  • null : is a value of a variable and is a type of object.
  • undefined : is a variable that has been declared but no value exists for it.
  • undeclared : is a variable that has been declared without the var, let, or const keyword.

72. What are some of the most popular Node.js packages you know of?

This answer can be unique to what you've used in the applications you've built. But below are some ideas for what you could respond with.

  • Express : A Node.js web application server framework, designed for building single-page, multi-page, and hybrid web applications. It is the standard server framework for node.js.
  • Request : Request is designed to be the simplest way possible to make HTTP calls.
  • Browserify : Browserify lets you require("modules") in the browser by bundling up all of your dependencies.
  • PM2 : PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.
  • Cheerio : A fast, flexible, and lean implementation of JQuery designed for use on the server.
  • Passport : Passport is authentication middleware for Node.js. Extremely flexible and modular, Passport can be unobtrusively dropped into any Express-based web application.
  • Nodemailer : Makes it easy to send emails from Node.js.

73. What's the purpose of the console object?

In Node.js, console is a global object used for printing different levels of messages to stdout and stderr . It also includes built-in ways to print informational, warning, and error messages.

74. What is the purpose of module.exports in Node.js?

The module.exports takes a JavaScript code file and exposes it to other files so they can import those functions or variables. Whatever variable or function you assign with module.exports or exports will be exposed as a module for other files.

75. How would you describe a monolithic application architecture?

A monolithic architecture means an app is built as one cohesive unit of code that has components that are designed to work together and share the same resources.

76. How would you describe a microservice application architecture?

A microservice architecture means an app is made up of lots of smaller, independent applications capable of running with their own resources and can scale independently from each other across multiple machines.

77. What are the pros and cons between a microservice and monolithic architecture?

Monolithic

Pros:

  • When everything is running through the same application, it's easy to hook up components to those cross-cutting concerns.
  • Shared-memory access is faster than inter-process communication, therefore there can be performance advantages.

Cons:

  • These applications tend to get entangled as the application evolves, which makes it hard to isolate different services.
  • Monolithic architectures become harder to understand the larger they get because of dependencies, side-effects, and magic that are now obvious unless you look at a specific part of the codebase.

Microservice

Pros:

  • Since each service is modularized and has its own specific job, microservice architectures are usually organized better.
  • They can result in better performance because you can isolate specific services and scale them individually from the rest of the application.

Cons:

  • Testing can be difficult since each service is running in its own environment.
  • Deployment complexity will be increased and the operational cost of deploying and managing the multiple services and systems will be increased as well.

78. Walk us through an application you've built?

Be prepared to walk-through an application you've listed on your resume. Make sure you can talk about the following:

  • The technologies you used to build the application (packages, testing frameworks, etc).
  • If you were part of a team, what role you had in building the application.
  • Explain both what design decisions you made and why they were made.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK